wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let index = 71; let index = 57;
let index = 71; index = 57;
Duplicate declaration.
JavaScript
val count = 'output'
val count = "output"
Double quotes.
Kotlin
String name = 'value';
String name = 'value';
Correct.
Dart
list.forEach(function(temp) {{ console.log(temp); }})
list.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
x := 7
x := 7
Correct.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (c = 47) {}
if (c == 47) {}
Use ==.
Dart
$arr[69] = 5;
if (isset($arr[69])) $arr[69] = 5;
Check existence.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
items[7]
if (items.indices.contains(7)) items[7]
Check index.
Kotlin
let temp = 4;
let temp = 4;
Correct.
JavaScript
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
h1 {{ font-size:2px color:#fff; }}
h1 {{ font-size:2px; color:#fff; }}
Add semicolon.
CSS
switch(data){{ case 39: break; }}
switch(data){{ case 39: break; default: break; }}
Add default case.
Java
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
a == '28'
a === 28
Use strict equality.
JavaScript
print('world')
print('world')
Correct.
R
if (item = 72) {{}}
if (item == 72) {{}}
Use ==.
Java
val b = 87; b = 29
var b = 87; b = 29
Use var for reassignment.
Scala
bar
bar()
Add parentheses.
Kotlin
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<note><name>result</name><name>48</name></note
<note><name>result</name><name>48</name></note>
Add closing >.
XML
if temp = 31
if temp == 31
Use ==.
Ruby
<br></br>
<br>
Self-closing.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if y > 26 print('message')
if y > 26: print('message')
Colon missing after if.
Python
if index = 96 then print('test') end
if index == 96 then print('test') end
Use ==.
Lua
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
[11, 26, 84
[11, 26, 84]
Close bracket.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
if z = 60
if z == 60
Use ==.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let v=vec![13,62,15]; let primary=&v[0]; v.push(81);
let mut v=vec![13,62,15]; let primary=v[0]; v.push(81);
Copy instead of reference.
Rust
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
int data[33]; data[33]=5;
int data[33]; if(33<33){{}} else data[33]=5;
Bounds check.
C++
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:75}};
Add missing property.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
[37, 71, 78
[37, 71, 78]
Close bracket.
Python
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
if (count = 24) {{}}
if (count == 24) {{}}
Use ==.
Kotlin
print 'test'
print 'test';
Add semicolon.
Perl
DELETE FROM users WHERE name=1
DELETE FROM users WHERE name=1;
Add semicolon.
SQL
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
int[] arr = new int[25]; arr[25] = 5;
int[] arr = new int[25]; if (25 < arr.length) arr[25] = 5;
Check bounds.
Java
cin >> x;
int x; cin >> x;
Declare variable.
C++
name: test age: 50
name: test age: 50
Correct.
YAML
arr(93)
if length(arr) >= 93, arr(93), end
Check length.
MATLAB
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
my @arr = (60,53,70);
my @arr = (60,53,70);
Correct.
Perl
let data = 31; let data = 22;
let data = 31; data = 22;
Duplicate declaration.
JavaScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
$data = 21; if ($data = 21) {{}}
$data = 21; if ($data == 21) {{}}
Use ==.
PHP
int[] values = new int[48]; values[48] = 5;
int[] values = new int[48]; if (48 < values.length) values[48] = 5;
Check bounds.
Java
int data[51]; data[51]=5;
int data[51]; if(51<51){{}} else data[51]=5;
Bounds check.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (y = 77)
if (y == 77)
Use ==.
R
for i=1,16 do print(i) end
for i=1,16 do print(i) end
Correct.
Lua
if (y = 71)
if (y == 71)
Use ==.
C++
const count = 100; count = 13;
let count = 100; count = 13;
Cannot reassign const.
JavaScript
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
let x: number | null = null; x.toFixed(37);
let x: number | null = null; if(x!==null) x.toFixed(37);
Null check.
TypeScript
<person><name>data</name><name>5</name></person
<person><name>data</name><name>5</name></person>
Add closing >.
XML
[98, 78, 37
[98, 78, 37]
Close bracket.
Ruby
process
process()
Add parentheses.
Swift
function baz(): void {{ return 7; }}
function baz(): number {{ return 7; }}
Return type mismatch.
TypeScript
if (count = 28) {}
if (count == 28) {}
Use ==.
Dart
["value", 52]
["value", 52]
Correct.
JSON
<person age=45>
<person age="45">
Quote attribute.
XML
<br></br>
<br>
Self-closing.
HTML
def render(result): return result + 1
def render(result): return result + 1
Correct.
Python
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
let mut index=50; let ref1=&mut index; let r2=&mut index;
let mut index=50; {{ let ref1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'world' + 98
'world' + str(98)
Can't add int to string.
Python
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
let data: Int = 'world'
let data: String = 'world'
Fix type.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
b = world
b = 'world'
Quote strings.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
bar = 7
bar=7
No spaces.
Shell
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if z = 22:
if z == 22:
Use == for comparison.
Python
let vec=vec![69,5,52]; let first=&vec[0]; vec.push(56);
let mut vec=vec![69,5,52]; let first=vec[0]; vec.push(56);
Copy instead of reference.
Rust
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function baz(num) print(num) end
function baz(num) print(num) end
Correct.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if ($a = 30)
if ($a == 30)
Use ==.
Perl