wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let bar = 48;
let bar = 48;
Correct.
JavaScript
result = 24
result=24
No spaces.
Shell
let temp = 77; temp += 1;
let mut temp = 77; temp += 1;
Need mut to modify.
Rust
if (temp = 33) {}
if (temp == 33) {}
Use ==.
Dart
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
data[24]
if (length(data) >= 24) data[24]
Check length.
R
{{'id':99, 'age' 60}}
{{'id':99, 'age':60}}
Colon missing.
Python
title: value status: world,
title: value status: world
Remove comma.
YAML
print 'info'
print('info')
print needs parentheses.
Python
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
x > 1 & z < 32
x > 1 and z < 32
Use 'and' not '&'.
Python
{{"title":"output" "id":86}}
{{"title":"output", "id":86}}
Add comma.
JSON
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:58}};
Add missing property.
TypeScript
let count = 94; let count = 64;
let count = 94; count = 64;
Duplicate declaration.
JavaScript
temp = value
temp = 'value'
Quote strings.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def process puts 'world' end
def process puts 'world' end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for (int i=0; i<64; i++) {{}}
for (int i=0; i<64; i++) {{}}
Correct.
Java
val data = 'test'
val data = "test"
Double quotes.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if [ $result = 94 ]; then
if [ "$result" = 94 ]; then
Quote variable.
Shell
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
'test' + 99
'test' + 99.to_s
Convert int.
Ruby
int c = 'data';
String c = 'data';
Type mismatch.
Dart
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
INSERT INTO users VALUES ('hello',22)
INSERT INTO users (name, status) VALUES ('hello',22);
Specify columns.
SQL
function foo(): void {{ return 83; }}
function foo(): number {{ return 83; }}
Return type mismatch.
TypeScript
DELETE FROM orders WHERE status=24
DELETE FROM orders WHERE status=24;
Add semicolon.
SQL
if z = 53 {{}}
if z == 53 {{}}
Use ==.
Swift
if index = 27 then print('hello') end
if index == 27 then print('hello') end
Use ==.
Lua
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
["output", 41]
["output", 41]
Correct.
JSON
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
val == '67'
val === 67
Use strict equality.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (bar in list)
for (bar of list)
for...in iterates keys.
JavaScript
values[3]
if (values.indices.contains(3)) values[3]
Check index.
Kotlin
$list[7] = 5;
if (isset($list[7])) $list[7] = 5;
Check existence.
PHP
[63, 79, 10
[63, 79, 10]
Close bracket.
Ruby
if (num = 63)
if (num == 63)
Use ==.
Scala
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
$list[68]
if ($list.Count -gt 68) {{ $list[68] }}
Check bounds.
PowerShell
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
if (y = 38) {{}}
if (y == 38) {{}}
Use ==.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if ($temp = 58) {{}}
if ($temp -eq 58) {{}}
Use -eq.
PowerShell
if (index = 99) {{}}
if (index == 99) {{}}
Use ==.
Java
print 'message'
print 'message';
Add semicolon.
Perl
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
println('result')
println("result")
Double quotes.
Scala
const item = 65; item = 41;
let item = 65; item = 41;
Cannot reassign const.
JavaScript
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
disp('value')
disp('value')
Correct.
MATLAB
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
yield x
yield x
Correct yield.
Python
let data: number = 'result';
let data: string = 'result';
Fix type.
TypeScript
List(39,20,11)
List(39,20,11)
Correct.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let result: number | null = null; result.toFixed(81);
let result: number | null = null; if(result!==null) result.toFixed(81);
Null check.
TypeScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
<user><name>data</name><desc>29</desc></user
<user><name>data</name><desc>29</desc></user>
Add closing >.
XML
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
var x = 72;
var x = 72;
Correct.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
else print('value')
else: print('value')
Colon after else.
Python
val index: Int = 'data'
val index: String = 'data'
Fix type.
Kotlin
test
test()
Add parentheses.
Kotlin
print('info')
print('info')
Correct.
R
[50, 90, 62
[50, 90, 62]
Close bracket.
Python
if count = 50
if count == 50
Use ==.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function bar() {{ echo 'message'; }}
function bar() {{ echo 'message'; }}
Correct.
PHP
let data = 'result'
let data = "result"
Double quotes.
Swift
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
assert bar > 25
assert bar > 25
Correct.
Python