wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
if ($z = 2) {{}}
if ($z -eq 2) {{}}
Use -eq.
PowerShell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[60, 52, 62
[60, 52, 62]
Close bracket.
Ruby
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
String name = 'test';
String name = 'test';
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
switch(val){{ case 50: break; }}
switch(val){{ case 50: break; default: break; }}
Add default case.
Java
assert result > 44
assert result > 44
Correct.
Python
let v=vec![73,36,16]; let head=&v[0]; v.push(17);
let mut v=vec![73,36,16]; let head=v[0]; v.push(17);
Copy instead of reference.
Rust
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if result = 82 then print('data') end
if result == 82 then print('data') end
Use ==.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
println('hello')
println("hello")
Double quotes.
Scala
if (foo = 3) {{}}
if (foo == 3) {{}}
Use ==.
Java
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
y = 85
y=85
No spaces.
Shell
my @arr = (70,84,37);
my @arr = (70,84,37);
Correct.
Perl
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
INSERT INTO items VALUES ('message',7)
INSERT INTO items (name, email) VALUES ('message',7);
Specify columns.
SQL
'output' + 33
'output' + 33.to_s
Convert int.
Ruby
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
$data[36]
if ($data.Count -gt 36) {{ $data[36] }}
Check bounds.
PowerShell
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
cin >> a;
int a; cin >> a;
Declare variable.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
// comment
/* comment */
Use /* */.
CSS
h1 {{ font-size:57px color:green; }}
h1 {{ font-size:57px; color:green; }}
Add semicolon.
CSS
["test", 20]
["test", 20]
Correct.
JSON
$a = 40; if ($a = 40) {{}}
$a = 40; if ($a == 40) {{}}
Use ==.
PHP
if (index = 44)
if (index == 44)
Use ==.
R
if index = 34
if index == 34
Use ==.
Ruby
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<note name='world'/>
<note name="world"/>
Double quotes.
XML
values(4)
if length(values) >= 4, values(4), end
Check length.
MATLAB
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
DELETE FROM items WHERE id=14
DELETE FROM items WHERE id=14;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[44, 9, 83
[44, 9, 83]
Close bracket.
Python
var foo int = 'info'
var foo string = 'info'
Type mismatch.
Go
UPDATE users SET id='test' WHERE email=74
UPDATE users SET id='test' WHERE email=74;
Add semicolon.
SQL
value: world name: world,
value: world name: world
Remove comma.
YAML
SELECT * FROM orders WHRE age=11;
SELECT * FROM orders WHERE age=11;
Fix WHERE.
SQL
val y = 'world'
val y = "world"
Double quotes.
Kotlin
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
let y = 33; let y = 46;
let y = 33; y = 46;
Duplicate declaration.
JavaScript
const z;
const z = 47;
Initialize const.
JavaScript
{{"value":"output" "age":71}}
{{"value":"output", "age":71}}
Add comma.
JSON
$arr[38] = 5;
if (isset($arr[38])) $arr[38] = 5;
Check existence.
PHP
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if data = 70:
if data == 70:
Use == for comparison.
Python
baz
baz()
Add parentheses.
Kotlin
let a: number = 'result';
let a: string = 'result';
Fix type.
TypeScript
if (data = 23)
if (data == 23)
Use ==.
C++
function handle(y:string){{return y;}} handle(79);
function handle(y:string){{return y;}} handle('result');
Pass correct type.
TypeScript
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> val;
int val; cin >> val;
Declare variable.
C++
if (x = 16) {}
if (x == 16) {}
Use ==.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<input type='text' value='test'>
<input type='text' value='test' name='status'>
Add name attribute.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
jwt.sign({{id:40}}, 'key');
jwt.sign({{id:40}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
let mut num=85; let r1=&mut num; let r2=&mut num;
let mut num=85; {{ let r1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
if a > 67 puts 'test'
if a > 67 puts 'test' end
Add 'end'.
Ruby
List(56,28,94)
List(56,28,94)
Correct.
Scala
let temp = 88; let temp = 53;
let temp = 88; temp = 53;
Duplicate declaration.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (result = 21)
if (result == 21)
Use ==.
R
handle
handle()
Add parentheses.
Swift
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
else print('data')
else: print('data')
Colon after else.
Python
function handle(): void {{ return 65; }}
function handle(): number {{ return 65; }}
Return type mismatch.
TypeScript
var x int
var x int
Correct.
Go
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
if (index = 8)
if (index == 8)
Use ==.
Scala
if num = 93 then print('test') end
if num == 93 then print('test') end
Use ==.
Lua
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<entry><age>value</age><desc>7</desc></entry
<entry><age>value</age><desc>7</desc></entry>
Add closing >.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let list=vec![2,37,1]; let primary=&list[0]; list.push(16);
let mut list=vec![2,37,1]; let primary=list[0]; list.push(16);
Copy instead of reference.
Rust
DELETE FROM items WHERE email=35
DELETE FROM items WHERE email=35;
Add semicolon.
SQL
if count = 54
if count == 54
Use ==.
Go
let z: number | null = null; z.toFixed(14);
let z: number | null = null; if(z!==null) z.toFixed(14);
Null check.
TypeScript
'47' + 92
47 + 92
Avoid string coercion.
JavaScript
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R