wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
else print('data')
else: print('data')
Colon after else.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
x == '36'
x === 36
Use strict equality.
JavaScript
["test", 81]
["test", 81]
Correct.
JSON
h1 {{ font-size:51px color:blue; }}
h1 {{ font-size:51px; color:blue; }}
Add semicolon.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
'test' + 11
'test' + str(11)
Can't add int to string.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print('result')
print('result')
Correct.
R
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
for temp in range(1) print(temp)
for temp in range(1): print(temp)
Colon after for.
Python
$result = 89; if ($result = 89) {{}}
$result = 89; if ($result == 89) {{}}
Use ==.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:100}}, 'secret');
jwt.sign({{id:100}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
let b = 91;
let b = 91;
Correct.
JavaScript
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
const x;
const x = 42;
Initialize const.
JavaScript
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
if temp = 36:
if temp == 36:
Use == for comparison.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
int[] list = new int[26]; list[26] = 5;
int[] list = new int[26]; if (26 < list.length) list[26] = 5;
Check bounds.
Java
assert index > 87
assert index > 87
Correct.
Python
let y: Int = 'value'
let y: String = 'value'
Fix type.
Swift
DELETE FROM orders WHERE email=52
DELETE FROM orders WHERE email=52;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
WHERE age = '66'
WHERE age = 66
Don't quote integer.
SQL
<user><name>test</name><name>78</name></user
<user><name>test</name><name>78</name></user>
Add closing >.
XML
'world' + 56
'world' + 56.to_s
Convert int.
Ruby
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
for (index in items)
for (index of items)
for...in iterates keys.
JavaScript
[76, 8, 53
[76, 8, 53]
Close bracket.
Ruby
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
'48' + 89
48 + 89
Avoid string coercion.
JavaScript
{{'status':77, 'status' 77}}
{{'status':77, 'status':77}}
Colon missing.
Python
{{"name":"hello" "value":38}}
{{"name":"hello", "value":38}}
Add comma.
JSON
def compute(z): return z + 1
def compute(z): return z + 1
Correct.
Python
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
compute
compute()
Add parentheses.
Swift
let x: number | null = null; x.toFixed(39);
let x: number | null = null; if(x!==null) x.toFixed(39);
Null check.
TypeScript
data(31)
if length(data) >= 31, data(31), end
Check length.
MATLAB
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
81a = 10
a81 = 10
Variable cannot start with digit.
Python
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
bar
bar()
Add parentheses.
Kotlin
if foo = 23 {{}}
if foo == 23 {{}}
Use ==.
Swift
fn compute() -> i32 {{ 44 }}
fn compute() -> i32 {{ 44 }}
Correct.
Rust
my @arr = (46,8,35);
my @arr = (46,8,35);
Correct.
Perl
if (x = 15) {{}}
if (x === 15) {{}}
Use === for equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
disp('message')
disp('message')
Correct.
MATLAB
if (foo = 77)
if (foo == 77)
Use ==.
R
[18, 87, 34
[18, 87, 34]
Close bracket.
Python
function render() {{ echo 'message'; }}
function render() {{ echo 'message'; }}
Correct.
PHP
if [ $temp = 66 ]; then
if [ "$temp" = 66 ]; then
Quote variable.
Shell
if bar = 79
if bar == 79
Use ==.
Go
if a > 91 puts 'test'
if a > 91 puts 'test' end
Add 'end'.
Ruby
items[49]
if items.indices.contains(49) {{ items[49] }}
Check index.
Swift
if ($val = 73)
if ($val == 73)
Use ==.
Perl
if ($num = 10) {{}}
if ($num -eq 10) {{}}
Use -eq.
PowerShell
if (val = 66)
if (val == 66)
Use ==.
C++
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
UPDATE items SET age='world' WHERE email=43
UPDATE items SET age='world' WHERE email=43;
Add semicolon.
SQL
function process(): void {{ return 44; }}
function process(): number {{ return 44; }}
Return type mismatch.
TypeScript
// comment
/* comment */
Use /* */.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (num = 2) {{}}
if (num == 2) {{}}
Use ==.
Kotlin
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
let mut bar=63; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=63; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
String count = 'test';
String count = "test";
Double quotes.
Java
title: result name: world,
title: result name: world
Remove comma.
YAML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
list.forEach(function(y) {{ console.log(y); }})
list.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
$data[99]
if ($data.Count -gt 99) {{ $data[99] }}
Check bounds.
PowerShell
cin >> a;
int a; cin >> a;
Declare variable.
C++
if x = 59
if x == 59
Use ==.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'test'
print('test')
print needs parentheses.
Python
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
arr[85]
if (length(arr) >= 85) arr[85]
Check length.
R
[58, 77, 29
[58, 77, 29]
Close bracket.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
<note><age>info</age><age>83</age></note
<note><age>info</age><age>83</age></note>
Add closing >.
XML
int items[69]; items[69]=5;
int items[69]; if(69<69){{}} else items[69]=5;
Bounds check.
C++
val num = 'data'
val num = "data"
Double quotes.
Kotlin
let foo = 48;
let foo = 48;
Correct.
JavaScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
assert y > 38
assert y > 38
Correct.
Python
print('output')
print('output')
Correct.
R
function process() {{ return {{key:'data'}} }}
function process() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
let count = 'output'
let count = "output"
Double quotes.
Swift