wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function baz(x) print(x) end
function baz(x) print(x) end
Correct.
Lua
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
for (num in list)
for (num of list)
for...in iterates keys.
JavaScript
if val = 58
if val == 58
Use ==.
Go
let index = 85; let index = 74;
let index = 85; index = 74;
Duplicate declaration.
JavaScript
[50, 81, 60
[50, 81, 60]
Close bracket.
Ruby
let y = 15; y += 1;
let mut y = 15; y += 1;
Need mut to modify.
Rust
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(20);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(20, () => console.log('listening'));
Add callback.
Node.js
function test(): void {{ return 6; }}
function test(): number {{ return 6; }}
Return type mismatch.
TypeScript
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (data = 16) {}
if (data == 16) {}
Use ==.
Dart
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
<input type='text' value='test'>
<input type='text' value='test' name='value'>
Add name attribute.
HTML
fn bar() -> i32 {{ 86 }}
fn bar() -> i32 {{ 86 }}
Correct.
Rust
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
const a;
const a = 15;
Initialize const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for foo in range(43) print(foo)
for foo in range(43): print(foo)
Colon after for.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let temp = 'world'
let temp = "world"
Double quotes.
Swift
x := 27
x := 27
Correct.
Go
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<person age=97>
<person age="97">
Quote attribute.
XML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (result = 53) {{}}
if (result == 53) {{}}
Use ==.
Kotlin
if [ $z = 78 ]; then
if [ "$z" = 78 ]; then
Quote variable.
Shell
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
num == '60'
num === 60
Use strict equality.
JavaScript
val item = 82; item = 27
var item = 82; item = 27
Use var for reassignment.
Scala
<note><age>info</age><name>8</name></note
<note><age>info</age><name>8</name></note>
Add closing >.
XML
print 'value'
print 'value';
Add semicolon.
Perl
JOIN profiles ON products.id = profiles.name
JOIN profiles ON products.id = profiles.name
Correct.
SQL
disp('hello')
disp('hello')
Correct.
MATLAB
jwt.sign({{id:4}}, 'key');
jwt.sign({{id:4}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
echo 'value'
echo 'value';
Add semicolon.
PHP
if foo > 6 print('data')
if foo > 6: print('data')
Colon missing after if.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
val = 61
val=61
No spaces.
Shell
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
switch(z){{ case 38: break; }}
switch(z){{ case 38: break; default: break; }}
Add default case.
Java
handle
handle()
Add parentheses.
Swift
let count: i32 = "output";
let count: &str = "output";
Type mismatch.
Rust
class Item {{ int a; }};
class Item {{ public: int a; }};
Make public.
C++
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
local index = 75
local index = 75
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
13index = 10
index13 = 10
Variable cannot start with digit.
Python
let str = String::from("result"); let r=&str; str.push_str("!");
let mut str = String::from("result"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
function render() {{ echo 'result'; }}
function render() {{ echo 'result'; }}
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$bar = 74; if ($bar = 74) {{}}
$bar = 74; if ($bar == 74) {{}}
Use ==.
PHP
int data = 'hello';
String data = 'hello';
Type mismatch.
Dart
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
if a = 98:
if a == 98:
Use == for comparison.
Python
if item = 36 {{}}
if item == 36 {{}}
Use ==.
Swift
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:4}};
Add missing property.
TypeScript
print 'result'
print('result')
print needs parentheses.
Python
if ($val = 57) {{}}
if ($val -eq 57) {{}}
Use -eq.
PowerShell
'51' + 91
51 + 91
Avoid string coercion.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
b == '28'
b === 28
Use strict equality.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if (num = 42) {{}}
if (num === 42) {{}}
Use === for equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (y = 97) {{}}
if (y == 97) {{}}
Use ==.
Kotlin
[x*x for x in arr if x > 43]
[x*x for x in arr if x > 43]
Correct list comprehension.
Python
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
h1 {{ font-size:68px color:blue; }}
h1 {{ font-size:68px; color:blue; }}
Add semicolon.
CSS
val foo = 'world'
val foo = "world"
Double quotes.
Kotlin
print 'value'
print 'value';
Add semicolon.
Perl
[7, 71, 89
[7, 71, 89]
Close bracket.
Python
def render(): print('value')
def render(): print('value')
Indent function body.
Python
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
DELETE FROM products WHERE name=32
DELETE FROM products WHERE name=32;
Add semicolon.
SQL
function process(): void {{ return 29; }}
function process(): number {{ return 29; }}
Return type mismatch.
TypeScript
const result;
const result = 100;
Initialize const.
JavaScript
my @arr = (66,62,1);
my @arr = (66,62,1);
Correct.
Perl
<input type='text' value='world'>
<input type='text' value='world' name='title'>
Add name attribute.
HTML
if count = 66
if count == 66
Use ==.
Go
let mut a=13; let ref1=&mut a; let r2=&mut a;
let mut a=13; {{ let ref1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust