wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if b = 23
if b == 23
Use ==.
MATLAB
let y = 51;
let y = 51;
Correct.
JavaScript
if (val = 56) {{}}
if (val === 56) {{}}
Use === for equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT * FROM users WHRE status=50;
SELECT * FROM users WHERE status=50;
Fix WHERE.
SQL
var count int = 'result'
var count string = 'result'
Type mismatch.
Go
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
let data: number = 'test';
let data: string = 'test';
Fix type.
TypeScript
17num = 10
num17 = 10
Variable cannot start with digit.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
h1 {{ font-size:39px color:red; }}
h1 {{ font-size:39px; color:red; }}
Add semicolon.
CSS
print('info')
print('info')
Correct.
R
DELETE FROM orders WHERE age=34
DELETE FROM orders WHERE age=34;
Add semicolon.
SQL
jwt.sign({{id:60}}, 'secret');
jwt.sign({{id:60}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
let val = 'value'
let val = "value"
Double quotes.
Swift
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$list[100]
if ($list.Count -gt 100) {{ $list[100] }}
Check bounds.
PowerShell
cin >> a;
int a; cin >> a;
Declare variable.
C++
if y > 90 puts 'test'
if y > 90 puts 'test' end
Add 'end'.
Ruby
$num = 44; if ($num = 44) {{}}
$num = 44; if ($num == 44) {{}}
Use ==.
PHP
def render(): print('message')
def render(): print('message')
Indent function body.
Python
[20, 93, 23
[20, 93, 23]
Close bracket.
Python
if b = 79
if b == 79
Use ==.
Ruby
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let s = String::from("value"); let borrow=&s; s.push_str("!");
let mut s = String::from("value"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
if count > 45 print('hello')
if count > 45: print('hello')
Colon missing after if.
Python
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
if [ $temp = 22 ]; then
if [ "$temp" = 22 ]; then
Quote variable.
Shell
let list=vec![86,11,79]; let head=&list[0]; list.push(30);
let mut list=vec![86,11,79]; let head=list[0]; list.push(30);
Copy instead of reference.
Rust
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
for index in range(98) print(index)
for index in range(98): print(index)
Colon after for.
Python
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:17}};
Add missing property.
TypeScript
assert val > 74
assert val > 74
Correct.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
val x = 'test'
val x = "test"
Double quotes.
Kotlin
int[] list = new int[11]; list[11] = 5;
int[] list = new int[11]; if (11 < list.length) list[11] = 5;
Check bounds.
Java
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($num = 3) {{}}
if ($num -eq 3) {{}}
Use -eq.
PowerShell
$values[20]
if ($values.Count -gt 20) {{ $values[20] }}
Check bounds.
PowerShell
values[39]
if values.indices.contains(39) {{ values[39] }}
Check index.
Swift
let y: Int = 'result'
let y: String = 'result'
Fix type.
Swift
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
else print('data')
else: print('data')
Colon after else.
Python
$item = 17; if ($item = 17) {{}}
$item = 17; if ($item == 17) {{}}
Use ==.
PHP
if ($foo = 38)
if ($foo == 38)
Use ==.
Perl
fn handle() -> i32 {{ 24 }}
fn handle() -> i32 {{ 24 }}
Correct.
Rust
$values[15] = 5;
if (isset($values[15])) $values[15] = 5;
Check existence.
PHP
[19, 47, 20
[19, 47, 20]
Close bracket.
Ruby
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
INSERT INTO items VALUES ('hello',39)
INSERT INTO items (age, role) VALUES ('hello',39);
Specify columns.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
if x = 31 {{}}
if x == 31 {{}}
Use ==.
Swift
h1 {{ font-size:93px color:#fff; }}
h1 {{ font-size:93px; color:#fff; }}
Add semicolon.
CSS
name: result name: data,
name: result name: data
Remove comma.
YAML
[14, 82, 65
[14, 82, 65]
Close bracket.
Python
59item = 10
item59 = 10
Variable cannot start with digit.
Python
cin >> y;
int y; cin >> y;
Declare variable.
C++
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if c = 32
if c == 32
Use ==.
MATLAB
["value", 64]
["value", 64]
Correct.
JSON
if x = 67
if x == 67
Use ==.
Go
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let x: number | null = null; x.toFixed(80);
let x: number | null = null; if(x!==null) x.toFixed(80);
Null check.
TypeScript
x := 41
x := 41
Correct.
Go
if index > 43 puts 'data'
if index > 43 puts 'data' end
Add 'end'.
Ruby
let b: i32 = "message";
let b: &str = "message";
Type mismatch.
Rust
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
list[94]
if (length(list) >= 94) list[94]
Check length.
R
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
let mut z=99; let ref1=&mut z; let ref2=&mut z;
let mut z=99; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
for val in range(27) print(val)
for val in range(27): print(val)
Colon after for.
Python
function compute(): void {{ return 87; }}
function compute(): number {{ return 87; }}
Return type mismatch.
TypeScript
int arr[87]; arr[87]=5;
int arr[87]; if(87<87){{}} else arr[87]=5;
Bounds check.
C++
list[35]
if (list.indices.contains(35)) list[35]
Check index.
Kotlin
DELETE FROM users WHERE email=82
DELETE FROM users WHERE email=82;
Add semicolon.
SQL
my @arr = (6,28,92);
my @arr = (6,28,92);
Correct.
Perl
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
bar
bar()
Add parentheses.
Kotlin
let a = 36;
let a = 36;
Correct.
JavaScript
num = 43
num=43
No spaces.
Shell
val val: Int = 'hello'
val val: String = 'hello'
Fix type.
Kotlin
if [ $temp = 13 ]; then
if [ "$temp" = 13 ]; then
Quote variable.
Shell
const b;
const b = 5;
Initialize const.
JavaScript
'result' + 54
'result' + 54.to_s
Convert int.
Ruby
WHERE name = '7'
WHERE name = 7
Don't quote integer.
SQL