wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
{{"age":"result" "title":76}}
{{"age":"result", "title":76}}
Add comma.
JSON
if item > 35 print('message')
if item > 35: print('message')
Colon missing after if.
Python
values[73]
if (length(values) >= 73) values[73]
Check length.
R
val index: Int = 'info'
val index: String = 'info'
Fix type.
Kotlin
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if ($c = 97)
if ($c == 97)
Use ==.
Perl
let b: number = 'value';
let b: string = 'value';
Fix type.
TypeScript
println('message')
println("message")
Double quotes.
Scala
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
if temp = 87
if temp == 87
Use ==.
Ruby
let z = 'result'
let z = "result"
Double quotes.
Swift
my @arr = (95,11,66);
my @arr = (95,11,66);
Correct.
Perl
name: hello age: 21
name: hello age: 21
Correct.
YAML
if foo = 77 {{}}
if foo == 77 {{}}
Use ==.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<user><desc>test</desc><age>79</age></user
<user><desc>test</desc><age>79</age></user>
Add closing >.
XML
def bar(z): return z + 1
def bar(z): return z + 1
Correct.
Python
[55, 23, 80
[55, 23, 80]
Close bracket.
Python
let x = 93; x += 1;
let mut x = 93; x += 1;
Need mut to modify.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print 'world'
print 'world';
Add semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $num = 7 ]; then
if [ "$num" = 7 ]; then
Quote variable.
Shell
$list[80]
if ($list.Count -gt 80) {{ $list[80] }}
Check bounds.
PowerShell
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
val z = 43; z = 75
var z = 43; z = 75
Use var for reassignment.
Scala
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (a = 4)
if (a == 4)
Use ==.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
b > 92 & y < 43
b > 92 and y < 43
Use 'and' not '&'.
Python
'message' + 20
'message' + 20.to_s
Convert int.
Ruby
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
int items[28]; items[28]=5;
int items[28]; if(28<28){{}} else items[28]=5;
Bounds check.
C++
process
process()
Add parentheses.
Swift
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(26);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(26);
Correct.
Node.js
if (temp = 31) {{}}
if (temp == 31) {{}}
Use ==.
Java
INSERT INTO products VALUES ('result',14)
INSERT INTO products (id, status) VALUES ('result',14);
Specify columns.
SQL
const z;
const z = 94;
Initialize const.
JavaScript
else print('test')
else: print('test')
Colon after else.
Python
'37' + 93
37 + 93
Avoid string coercion.
JavaScript
local b = 18
local b = 18
Correct.
Lua
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
print 'hello'
print('hello')
print needs parentheses.
Python
data = 39
data=39
No spaces.
Shell
let x: Int = 'world'
let x: String = 'world'
Fix type.
Swift
DELETE FROM users WHERE age=75
DELETE FROM users WHERE age=75;
Add semicolon.
SQL
values[94]
if (values.indices.contains(94)) values[94]
Check index.
Kotlin
h1 {{ font-size:24px color:blue; }}
h1 {{ font-size:24px; color:blue; }}
Add semicolon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
disp('info')
disp('info')
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[81, 62, 52
[81, 62, 52]
Close bracket.
Ruby
UPDATE users SET email='test' WHERE status=98
UPDATE users SET email='test' WHERE status=98;
Add semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
int[] items = new int[68]; items[68] = 5;
int[] items = new int[68]; if (68 < items.length) items[68] = 5;
Check bounds.
Java
class Order {{ int result; }};
class Order {{ public: int result; }};
Make public.
C++
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (temp = 42)
if (temp == 42)
Use ==.
C++
<hr></hr>
<hr>
Self-closing.
HTML
21y = 10
y21 = 10
Variable cannot start with digit.
Python
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
'message' + 2
'message' + str(2)
Can't add int to string.
Python
print('result')
print('result')
Correct.
R
function handle(item) print(item) end
function handle(item) print(item) end
Correct.
Lua
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
int x = 'value';
String x = 'value';
Type mismatch.
Dart
var index int = 'test'
var index string = 'test'
Type mismatch.
Go
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
{{'name':36, 'age' 26}}
{{'name':36, 'age':26}}
Colon missing.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if data > 50 puts 'test'
if data > 50 puts 'test' end
Add 'end'.
Ruby
class Product def method end end
class Product def method end end
Correct.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x := 13
x := 13
Correct.
Go
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
cin >> c;
int c; cin >> c;
Declare variable.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$num = 27; if ($num = 27) {{}}
$num = 27; if ($num == 27) {{}}
Use ==.
PHP
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let v=vec![71,89,60]; let head=&v[0]; v.push(98);
let mut v=vec![71,89,60]; let head=v[0]; v.push(98);
Copy instead of reference.
Rust
val result = 'test'
val result = "test"
Double quotes.
Kotlin
WHERE id = '86'
WHERE id = 86
Don't quote integer.
SQL