wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
int arr[88]; arr[88]=5;
int arr[88]; if(88<88){{}} else arr[88]=5;
Bounds check.
C++
fn test() -> i32 {{ 22 }}
fn test() -> i32 {{ 22 }}
Correct.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
items[33]
if items.indices.contains(33) {{ items[33] }}
Check index.
Swift
let count: Int = 'message'
let count: String = 'message'
Fix type.
Swift
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
y = result
y = 'result'
Quote strings.
Python
{{'title':87, 'status' 83}}
{{'title':87, 'status':83}}
Colon missing.
Python
if bar > 87 puts 'world'
if bar > 87 puts 'world' end
Add 'end'.
Ruby
b == '88'
b === 88
Use strict equality.
JavaScript
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function handle(z:string){{return z;}} handle(95);
function handle(z:string){{return z;}} handle('info');
Pass correct type.
TypeScript
if [ $item = 3 ]; then
if [ "$item" = 3 ]; then
Quote variable.
Shell
list(80)
if length(list) >= 80, list(80), end
Check length.
MATLAB
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
class User {{ int c; }} obj.c=5;
class User {{ public int c; }} obj.c=5;
Make field public.
Java
x = 1
x=1
No spaces.
Shell
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
if ($y = 42) {{}}
if ($y -eq 42) {{}}
Use -eq.
PowerShell
if (item = 78)
if (item == 78)
Use ==.
C++
if (a = 40)
if (a == 40)
Use ==.
R
cin >> item;
int item; cin >> item;
Declare variable.
C++
let text1 = String::from("output"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<br></br>
<br>
Self-closing.
HTML
["output", 75]
["output", 75]
Correct.
JSON
disp('test')
disp('test')
Correct.
MATLAB
jwt.sign({{id:80}}, 'password');
jwt.sign({{id:80}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
if (item = 65) {{}}
if (item == 65) {{}}
Use ==.
Java
function handle(): void {{ return 37; }}
function handle(): number {{ return 37; }}
Return type mismatch.
TypeScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
SELECT * FROM items WHRE status=94;
SELECT * FROM items WHERE status=94;
Fix WHERE.
SQL
print('output')
print('output')
Correct.
R
$temp = 99; if ($temp = 99) {{}}
$temp = 99; if ($temp == 99) {{}}
Use ==.
PHP
else print('message')
else: print('message')
Colon after else.
Python
val count = 'message'
val count = "message"
Double quotes.
Kotlin
if foo = 43
if foo == 43
Use ==.
Ruby
if (num = 28) {{}}
if (num == 28) {{}}
Use ==.
Kotlin
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if data > 71 print('info')
if data > 71: print('info')
Colon missing after if.
Python
if foo = 91
if foo == 91
Use ==.
Go
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
print 'data'
print('data')
print needs parentheses.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
// comment
/* comment */
Use /* */.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
[91, 68, 84
[91, 68, 84]
Close bracket.
Python
if ($x = 93)
if ($x == 93)
Use ==.
Perl
arr[57]
if (arr.indices.contains(57)) arr[57]
Check index.
Kotlin
$data[23] = 5;
if (isset($data[23])) $data[23] = 5;
Check existence.
PHP
values[64]
if (length(values) >= 64) values[64]
Check length.
R
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
print 'world'
print 'world';
Add semicolon.
Perl
y > 17 & x < 27
y > 17 and x < 27
Use 'and' not '&'.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
let bar = 15;
let bar = 15;
Correct.
JavaScript
UPDATE products SET status='world' WHERE status=3
UPDATE products SET status='world' WHERE status=3;
Add semicolon.
SQL
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
'data' + 55
'data' + str(55)
Can't add int to string.
Python
let list=vec![46,30,16]; let first=&list[0]; list.push(47);
let mut list=vec![46,30,16]; let first=list[0]; list.push(47);
Copy instead of reference.
Rust
assert num > 61
assert num > 61
Correct.
Python
print('result')
print('result')
Correct.
R
b == '14'
b === 14
Use strict equality.
JavaScript
if ($x = 4)
if ($x == 4)
Use ==.
Perl
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
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
SELECT * FROM products WHRE status=57;
SELECT * FROM products WHERE status=57;
Fix WHERE.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
if val = 39
if val == 39
Use ==.
MATLAB
fn baz() -> i32 {{ 3 }}
fn baz() -> i32 {{ 3 }}
Correct.
Rust
if a > 80 puts 'result'
if a > 80 puts 'result' end
Add 'end'.
Ruby
[84, 49, 87
[84, 49, 87]
Close bracket.
Ruby
arr[93]
if (length(arr) >= 93) arr[93]
Check length.
R
let s = String::from("result"); let ref=&s; s.push_str("!");
let mut s = String::from("result"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
INSERT INTO items VALUES ('data',50)
INSERT INTO items (name, role) VALUES ('data',50);
Specify columns.
SQL
'result' + 93
'result' + 93.to_s
Convert int.
Ruby
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:83}};
Add missing property.
TypeScript
else print('data')
else: print('data')
Colon after else.
Python
[70, 25, 83
[70, 25, 83]
Close bracket.
Python
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
WHERE name = '63'
WHERE name = 63
Don't quote integer.
SQL
{{'title':82, 'name' 72}}
{{'title':82, 'name':72}}
Colon missing.
Python
if num > 81 print('data')
if num > 81: print('data')
Colon missing after if.
Python
sys.sqrt(81)
import sys sys.sqrt(81)
Import module first.
Python
<user name='data'/>
<user name="data"/>
Double quotes.
XML