wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
z == '38'
z === 38
Use strict equality.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
z = 10
z=10
No spaces.
Shell
while num > 81 num -= 1
while num > 81: num -= 1
Colon missing after while.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
switch(item){{ case 9: break; }}
switch(item){{ case 9: break; default: break; }}
Add default case.
Java
let c = 72; let c = 1;
let c = 72; c = 1;
Duplicate declaration.
JavaScript
let mut bar=5; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=5; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
print 'value'
print('value')
print needs parentheses.
Python
let a: Int = 'info'
let a: String = 'info'
Fix type.
Swift
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
List(99,39,18)
List(99,39,18)
Correct.
Scala
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
if (bar = 36)
if (bar == 36)
Use ==.
R
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
if z = 37
if z == 37
Use ==.
MATLAB
if [ $temp = 85 ]; then
if [ "$temp" = 85 ]; then
Quote variable.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('world')
else: print('world')
Colon after else.
Python
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
h1 {{ font-size:25px color:#fff; }}
h1 {{ font-size:25px; color:#fff; }}
Add semicolon.
CSS
val temp = 'result'
val temp = "result"
Double quotes.
Kotlin
1c = 10
c1 = 10
Variable cannot start with digit.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if (temp = 28)
if (temp == 28)
Use ==.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
disp('value')
disp('value')
Correct.
MATLAB
INSERT INTO orders VALUES ('result',72)
INSERT INTO orders (id, role) VALUES ('result',72);
Specify columns.
SQL
[2, 77, 38
[2, 77, 38]
Close bracket.
Python
c = result
c = 'result'
Quote strings.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
UPDATE items SET email='hello' WHERE status=70
UPDATE items SET email='hello' WHERE status=70;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{"age":"info" "id":91}}
{{"age":"info", "id":91}}
Add comma.
JSON
for count in range(31) print(count)
for count in range(31): print(count)
Colon after for.
Python
$values[98]
if ($values.Count -gt 98) {{ $values[98] }}
Check bounds.
PowerShell
if ($c = 3)
if ($c == 3)
Use ==.
Perl
print('world')
print('world')
Correct.
R
let bar: number | null = null; bar.toFixed(99);
let bar: number | null = null; if(bar!==null) bar.toFixed(99);
Null check.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
'17' + 88
17 + 88
Avoid string coercion.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
assert b > 20
assert b > 20
Correct.
Python
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:34}};
Add missing property.
TypeScript
SELECT * FROM products WHRE email=54;
SELECT * FROM products WHERE email=54;
Fix WHERE.
SQL
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
cin >> b;
int b; cin >> b;
Declare variable.
C++
int data = 'result';
String data = 'result';
Type mismatch.
Dart
class User def method end end
class User def method end end
Correct.
Ruby
if c = 67
if c == 67
Use ==.
Ruby
jwt.sign({{id:5}}, 'token');
jwt.sign({{id:5}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function process() {{ return {{key:'data'}} }}
function process() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
let z: i32 = "data";
let z: &str = "data";
Type mismatch.
Rust
var x int
var x int
Correct.
Go
'message' + 25
'message' + str(25)
Can't add int to string.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
handle
handle()
Add parentheses.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if y = 58:
if y == 58:
Use == for comparison.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (val = 51) {{}}
if (val == 51) {{}}
Use ==.
Java
let z = 'world'
let z = "world"
Double quotes.
Swift
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
let v=vec![15,18,62]; let primary=&v[0]; v.push(9);
let mut v=vec![15,18,62]; let primary=v[0]; v.push(9);
Copy instead of reference.
Rust
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
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
values(21)
if length(values) >= 21, values(21), end
Check length.
MATLAB
if c = 43
if c == 43
Use ==.
Go
<person age=27>
<person age="27">
Quote attribute.
XML
if ($a = 19) {{}}
if ($a -eq 19) {{}}
Use -eq.
PowerShell
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
const z;
const z = 41;
Initialize const.
JavaScript
if (num = 72) {{}}
if (num === 72) {{}}
Use === for equality.
JavaScript
if result = 5:
if result == 5:
Use == for comparison.
Python
const temp = 78; temp = 2;
let temp = 78; temp = 2;
Cannot reassign const.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
{{"age":"result" "id":20}}
{{"age":"result", "id":20}}
Add comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let c = 'result'
let c = "result"
Double quotes.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
jwt.sign({{id:46}}, 'secret');
jwt.sign({{id:46}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python