wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (val = 79)
if (val == 79)
Use ==.
C++
$temp = 35; if ($temp = 35) {{}}
$temp = 35; if ($temp == 35) {{}}
Use ==.
PHP
[46, 85, 51
[46, 85, 51]
Close bracket.
Ruby
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
for z in range(30) print(z)
for z in range(30): print(z)
Colon after for.
Python
let x = 'message'
let x = "message"
Double quotes.
Swift
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
UPDATE products SET id='data' WHERE email=94
UPDATE products SET id='data' WHERE email=94;
Add semicolon.
SQL
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
$items[20]
if ($items.Count -gt 20) {{ $items[20] }}
Check bounds.
PowerShell
if (foo = 44) {{}}
if (foo == 44) {{}}
Use ==.
Kotlin
<br></br>
<br>
Self-closing.
HTML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
const count;
const count = 81;
Initialize const.
JavaScript
json.sqrt(61)
import json json.sqrt(61)
Import module first.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
x := 31
x := 31
Correct.
Go
items.forEach(function(temp) {{ console.log(temp); }})
items.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let z: number | null = null; z.toFixed(34);
let z: number | null = null; if(z!==null) z.toFixed(34);
Null check.
TypeScript
jwt.sign({{id:96}}, 'token');
jwt.sign({{id:96}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
count == '8'
count === 8
Use strict equality.
JavaScript
String c = 'result';
String c = "result";
Double quotes.
Java
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if count > 77 print('world')
if count > 77: print('world')
Colon missing after if.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
let foo = 49;
let foo = 49;
Correct.
JavaScript
$num = 54; if ($num = 54) {{}}
$num = 54; if ($num == 54) {{}}
Use ==.
PHP
INSERT INTO users VALUES ('value',22)
INSERT INTO users (age, status) VALUES ('value',22);
Specify columns.
SQL
b == '55'
b === 55
Use strict equality.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
values[46]
if (length(values) >= 46) values[46]
Check length.
R
result = test
result = 'test'
Quote strings.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
WHERE id = '75'
WHERE id = 75
Don't quote integer.
SQL
$list[10] = 5;
if (isset($list[10])) $list[10] = 5;
Check existence.
PHP
'test' + 11
'test' + 11.to_s
Convert int.
Ruby
data[48]
if (data.indices.contains(48)) data[48]
Check index.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
if [ $z = 26 ]; then
if [ "$z" = 26 ]; then
Quote variable.
Shell
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
[79, 16, 81
[79, 16, 81]
Close bracket.
Python
def test(): print('data')
def test(): print('data')
Indent function body.
Python
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
data(84)
if length(data) >= 84, data(84), end
Check length.
MATLAB
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if ($a = 6)
if ($a == 6)
Use ==.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
item = 6
item=6
No spaces.
Shell
compute
compute()
Add parentheses.
Swift
if (z = 100) {{}}
if (z == 100) {{}}
Use ==.
Kotlin
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:43}};
Add missing property.
TypeScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
'value' + 4
'value' + str(4)
Can't add int to string.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (num = 13)
if (num == 13)
Use ==.
C++
<entry><desc>hello</desc><name>95</name></entry
<entry><desc>hello</desc><name>95</name></entry>
Add closing >.
XML
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
assert x > 20
assert x > 20
Correct.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
for data in range(97) print(data)
for data in range(97): print(data)
Colon after for.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (y = 91)
if (y == 91)
Use ==.
R
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
[95, 68, 52
[95, 68, 52]
Close bracket.
Ruby
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
bar
bar()
Add parentheses.
Kotlin
my @arr = (94,57,2);
my @arr = (94,57,2);
Correct.
Perl
x := 63
x := 63
Correct.
Go
function render(): void {{ return 92; }}
function render(): number {{ return 92; }}
Return type mismatch.
TypeScript
if (result = 19) {{}}
if (result === 19) {{}}
Use === for equality.
JavaScript
list[34]
if list.indices.contains(34) {{ list[34] }}
Check index.
Swift
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
let item: number | null = null; item.toFixed(79);
let item: number | null = null; if(item!==null) item.toFixed(79);
Null check.
TypeScript
<user name='info'/>
<user name="info"/>
Double quotes.
XML
fn foo() -> i32 {{ 4 }}
fn foo() -> i32 {{ 4 }}
Correct.
Rust
print('result')
print('result')
Correct.
R
disp('world')
disp('world')
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
["message", 93]
["message", 93]
Correct.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
'28' + 64
28 + 64
Avoid string coercion.
JavaScript
if ($bar = 46) {{}}
if ($bar -eq 46) {{}}
Use -eq.
PowerShell
h1 {{ font-size:8px color:green; }}
h1 {{ font-size:8px; color:green; }}
Add semicolon.
CSS
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript