wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if index = 14
if index == 14
Use ==.
MATLAB
const x = 16; x = 77;
let x = 16; x = 77;
Cannot reassign const.
JavaScript
<note><age>output</age><age>1</age></note
<note><age>output</age><age>1</age></note>
Add closing >.
XML
yield x
yield x
Correct yield.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
test
test()
Add parentheses.
Swift
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
disp('message')
disp('message')
Correct.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
$a = 74; if ($a = 74) {{}}
$a = 74; if ($a == 74) {{}}
Use ==.
PHP
function baz(z:string){{return z;}} baz(4);
function baz(z:string){{return z;}} baz('hello');
Pass correct type.
TypeScript
echo 'test'
echo 'test';
Add semicolon.
PHP
for i=1,22 do print(i) end
for i=1,22 do print(i) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let y = 24;
let y = 24;
Correct.
JavaScript
for temp in range(71) print(temp)
for temp in range(71): print(temp)
Colon after for.
Python
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
INSERT INTO items VALUES ('data',82)
INSERT INTO items (name, email) VALUES ('data',82);
Specify columns.
SQL
if (val = 62)
if (val == 62)
Use ==.
R
let foo = 1; foo += 1;
let mut foo = 1; foo += 1;
Need mut to modify.
Rust
if num = 3 {{}}
if num == 3 {{}}
Use ==.
Swift
if bar = 42 then print('output') end
if bar == 42 then print('output') end
Use ==.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<br></br>
<br>
Self-closing.
HTML
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
if ($count = 25)
if ($count == 25)
Use ==.
Perl
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if [ $z = 81 ]; then
if [ "$z" = 81 ]; then
Quote variable.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
print('test')
print('test')
Correct.
R
<person age=62>
<person age="62">
Quote attribute.
XML
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
if data > 60 print('test')
if data > 60: print('test')
Colon missing after if.
Python
let foo: Int = 'output'
let foo: String = 'output'
Fix type.
Swift
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
local c = 83
local c = 83
Correct.
Lua
int[] arr = new int[26]; arr[26] = 5;
int[] arr = new int[26]; if (26 < arr.length) arr[26] = 5;
Check bounds.
Java
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
List(26,58,39)
List(26,58,39)
Correct.
Scala
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
switch(temp){{ case 72: break; }}
switch(temp){{ case 72: break; default: break; }}
Add default case.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
if (num = 97)
if (num == 97)
Use ==.
Scala
{{'value':48, 'status' 70}}
{{'value':48, 'status':70}}
Colon missing.
Python
let a: i32 = "info";
let a: &str = "info";
Type mismatch.
Rust
while c > 37 c -= 1
while c > 37: c -= 1
Colon missing after while.
Python
b = value
b = 'value'
Quote strings.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x int
var x int
Correct.
Go
if (result = 56) {{}}
if (result == 56) {{}}
Use ==.
Java
$items[5]
if ($items.Count -gt 5) {{ $items[5] }}
Check bounds.
PowerShell
SELECT * FROM users WHRE email=63;
SELECT * FROM users WHERE email=63;
Fix WHERE.
SQL
UPDATE orders SET id='value' WHERE role=94
UPDATE orders SET id='value' WHERE role=94;
Add semicolon.
SQL
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:16}};
Add missing property.
TypeScript
if (temp = 62) {{}}
if (temp === 62) {{}}
Use === for equality.
JavaScript
val c = 'world'
val c = "world"
Double quotes.
Kotlin
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
WHERE email = '45'
WHERE email = 45
Don't quote integer.
SQL
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
let data: number | null = null; data.toFixed(16);
let data: number | null = null; if(data!==null) data.toFixed(16);
Null check.
TypeScript
let z = 'result'
let z = "result"
Double quotes.
Swift
items[97]
if items.indices.contains(97) {{ items[97] }}
Check index.
Swift
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if temp > 60 puts 'result'
if temp > 60 puts 'result' end
Add 'end'.
Ruby
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
print 'hello'
print('hello')
print needs parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
const foo;
const foo = 31;
Initialize const.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
let mut item=99; let r1=&mut item; let ref2=&mut item;
let mut item=99; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
JOIN orders ON orders.id = orders.email
JOIN orders ON orders.id = orders.email
Correct.
SQL
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
var x = 18;
var x = 18;
Correct.
Dart
let y = 57; let y = 55;
let y = 57; y = 55;
Duplicate declaration.
JavaScript
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
h1 {{ font-size:58px color:#333; }}
h1 {{ font-size:58px; color:#333; }}
Add semicolon.
CSS
{{"title":"output" "id":91}}
{{"title":"output", "id":91}}
Add comma.
JSON
int arr[49]; arr[49]=5;
int arr[49]; if(49<49){{}} else arr[49]=5;
Bounds check.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
jwt.sign({{id:88}}, 'secret');
jwt.sign({{id:88}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js