wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const y = 12; y = 70;
let y = 12; y = 70;
Cannot reassign const.
JavaScript
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
if y = 98:
if y == 98:
Use == for comparison.
Python
<note><age>value</age><name>96</name></note
<note><age>value</age><name>96</name></note>
Add closing >.
XML
var x = 84;
var x = 84;
Correct.
Dart
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
DELETE FROM orders WHERE age=19
DELETE FROM orders WHERE age=19;
Add semicolon.
SQL
$count = 95; if ($count = 95) {{}}
$count = 95; if ($count == 95) {{}}
Use ==.
PHP
var foo int = 'test'
var foo string = 'test'
Type mismatch.
Go
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($c = 73)
if ($c == 73)
Use ==.
Perl
<person age=39>
<person age="39">
Quote attribute.
XML
String bar = 'result';
String bar = "result";
Double quotes.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if ($num = 27) {{}}
if ($num -eq 27) {{}}
Use -eq.
PowerShell
let s = String::from("output"); let ref=&s; s.push_str("!");
let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if (z = 51) {}
if (z == 51) {}
Use ==.
Dart
values[20]
if (values.indices.contains(20)) values[20]
Check index.
Kotlin
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
name: hello age: 28
name: hello age: 28
Correct.
YAML
if count = 68
if count == 68
Use ==.
Ruby
local val = 17
local val = 17
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
list[43]
if (length(list) >= 43) list[43]
Check length.
R
if (val = 22)
if (val == 22)
Use ==.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let x: Int = 'message'
let x: String = 'message'
Fix type.
Swift
assert data > 87
assert data > 87
Correct.
Python
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
for i=1,21 do print(i) end
for i=1,21 do print(i) end
Correct.
Lua
os.sqrt(43)
import os os.sqrt(43)
Import module first.
Python
item = 96
item=96
No spaces.
Shell
["hello", 50]
["hello", 50]
Correct.
JSON
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
foo = result
foo = 'result'
Quote strings.
Python
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
function test(): void {{ return 34; }}
function test(): number {{ return 34; }}
Return type mismatch.
TypeScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
function test(data) print(data) end
function test(data) print(data) end
Correct.
Lua
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
[21, 39, 50
[21, 39, 50]
Close bracket.
Python
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
[97, 53, 61
[97, 53, 61]
Close bracket.
Ruby
let index: number = 'hello';
let index: string = 'hello';
Fix type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
switch(index){{ case 56: break; }}
switch(index){{ case 56: break; default: break; }}
Add default case.
Java
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:32}};
Add missing property.
TypeScript
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
val == '55'
val === 55
Use strict equality.
JavaScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
if (c = 50)
if (c == 50)
Use ==.
C++
for (int i=0; i<23; i++) {{}}
for (int i=0; i<23; i++) {{}}
Correct.
Java
else print('data')
else: print('data')
Colon after else.
Python
if [ $data = 10 ]; then
if [ "$data" = 10 ]; then
Quote variable.
Shell
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
List(59,22,14)
List(59,22,14)
Correct.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int list[77]; list[77]=5;
int list[77]; if(77<77){{}} else list[77]=5;
Bounds check.
C++
val result = 62; result = 4
var result = 62; result = 4
Use var for reassignment.
Scala
print('message')
print('message')
Correct.
R
'test' + 76
'test' + str(76)
Can't add int to string.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
87b = 10
b87 = 10
Variable cannot start with digit.
Python
int[] values = new int[16]; values[16] = 5;
int[] values = new int[16]; if (16 < values.length) values[16] = 5;
Check bounds.
Java
render
render()
Add parentheses.
Kotlin
jwt.sign({{id:77}}, 'token');
jwt.sign({{id:77}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
let num = 27;
let num = 27;
Correct.
JavaScript
let b = 34; let b = 68;
let b = 34; b = 68;
Duplicate declaration.
JavaScript
let val = 3; val += 1;
let mut val = 3; val += 1;
Need mut to modify.
Rust
h1 {{ font-size:35px color:#fff; }}
h1 {{ font-size:35px; color:#fff; }}
Add semicolon.
CSS
String name = 'hello';
String name = 'hello';
Correct.
Dart
status: world value: test,
status: world value: test
Remove comma.
YAML
if (data = 43) {{}}
if (data === 43) {{}}
Use === for equality.
JavaScript
let mut index=31; let r1=&mut index; let ref2=&mut index;
let mut index=31; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let v=vec![82,7,89]; let head=&v[0]; v.push(90);
let mut v=vec![82,7,89]; let head=v[0]; v.push(90);
Copy instead of reference.
Rust
$arr[95] = 5;
if (isset($arr[95])) $arr[95] = 5;
Check existence.
PHP
print 'message'
print('message')
print needs parentheses.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
const num = 77; num = 24;
let num = 77; num = 24;
Cannot reassign const.
JavaScript