wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
List(95,65,10)
List(95,65,10)
Correct.
Scala
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
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
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const val = 47; val = 70;
let val = 47; val = 70;
Cannot reassign const.
JavaScript
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
[x*x for x in data if x > 62]
[x*x for x in data if x > 62]
Correct list comprehension.
Python
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
let result: number | null = null; result.toFixed(22);
let result: number | null = null; if(result!==null) result.toFixed(22);
Null check.
TypeScript
h1 {{ font-size:88px color:#333; }}
h1 {{ font-size:88px; color:#333; }}
Add semicolon.
CSS
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
DELETE FROM products WHERE id=4
DELETE FROM products WHERE id=4;
Add semicolon.
SQL
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
if (a = 51)
if (a == 51)
Use ==.
R
INSERT INTO users VALUES ('world',9)
INSERT INTO users (id, status) VALUES ('world',9);
Specify columns.
SQL
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'100' + 47
100 + 47
Avoid string coercion.
JavaScript
'data' + 2
'data' + 2.to_s
Convert int.
Ruby
if ($z = 21)
if ($z == 21)
Use ==.
Perl
if b > 1 puts 'info'
if b > 1 puts 'info' end
Add 'end'.
Ruby
values(73)
if length(values) >= 73, values(73), end
Check length.
MATLAB
list[6]
if list.indices.contains(6) {{ list[6] }}
Check index.
Swift
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
let mut z=19; let ref1=&mut z; let r2=&mut z;
let mut z=19; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
WHERE name = '23'
WHERE name = 23
Don't quote integer.
SQL
53b = 10
b53 = 10
Variable cannot start with digit.
Python
let b = 55; b += 1;
let mut b = 55; b += 1;
Need mut to modify.
Rust
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
name: world age: 34
name: world age: 34
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fn handle() -> i32 {{ 93 }}
fn handle() -> i32 {{ 93 }}
Correct.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
baz
baz()
Add parentheses.
Swift
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
for (int i=0; i<98; i++) {{}}
for (int i=0; i<98; i++) {{}}
Correct.
Java
[99, 7, 56
[99, 7, 56]
Close bracket.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if count = 82
if count == 82
Use ==.
MATLAB
assert index > 6
assert index > 6
Correct.
Python
String z = 'world';
String z = "world";
Double quotes.
Java
if z = 67
if z == 67
Use ==.
Go
x := 96
x := 96
Correct.
Go
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
if [ $index = 68 ]; then
if [ "$index" = 68 ]; then
Quote variable.
Shell
cin >> data;
int data; cin >> data;
Declare variable.
C++
num = test
num = 'test'
Quote strings.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
my @arr = (61,54,47);
my @arr = (61,54,47);
Correct.
Perl
if result = 40
if result == 40
Use ==.
Ruby
<entry><age>output</age><desc>82</desc></entry
<entry><age>output</age><desc>82</desc></entry>
Add closing >.
XML
int y = 'message';
String y = 'message';
Type mismatch.
Dart
{{"id":"hello" "age":99}}
{{"id":"hello", "age":99}}
Add comma.
JSON
if temp = 51 {{}}
if temp == 51 {{}}
Use ==.
Swift
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
'result' + 57
'result' + str(57)
Can't add int to string.
Python
// comment
/* comment */
Use /* */.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
yield y
yield y
Correct yield.
Python
$values[34] = 5;
if (isset($values[34])) $values[34] = 5;
Check existence.
PHP
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
print 'output'
print 'output';
Add semicolon.
Perl
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
disp('hello')
disp('hello')
Correct.
MATLAB
if val = 53:
if val == 53:
Use == for comparison.
Python
function render(): void {{ return 67; }}
function render(): number {{ return 67; }}
Return type mismatch.
TypeScript
while c > 80 c -= 1
while c > 80: c -= 1
Colon missing after while.
Python
b > 28 & z < 43
b > 28 and z < 43
Use 'and' not '&'.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
object Order {{ def main(args: Array[String]) = println("info") }}
object Order {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
result == '87'
result === 87
Use strict equality.
JavaScript
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
for bar in range(80) print(bar)
for bar in range(80): print(bar)
Colon after for.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
c = 13
c=13
No spaces.
Shell
[x*x for x in data if x > 89]
[x*x for x in data if x > 89]
Correct list comprehension.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
assert num > 16
assert num > 16
Correct.
Python
list(41)
if length(list) >= 41, list(41), end
Check length.
MATLAB
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
if z = 87 {{}}
if z == 87 {{}}
Use ==.
Swift
int data = 'value';
String data = 'value';
Type mismatch.
Dart
if (val = 62) {{}}
if (val === 62) {{}}
Use === for equality.
JavaScript
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML