wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
$b = 21; if ($b = 21) {{}}
$b = 21; if ($b == 21) {{}}
Use ==.
PHP
if count = 81
if count == 81
Use ==.
Ruby
// comment
/* comment */
Use /* */.
CSS
const y;
const y = 89;
Initialize const.
JavaScript
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
y == '22'
y === 22
Use strict equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
$items[2]
if ($items.Count -gt 2) {{ $items[2] }}
Check bounds.
PowerShell
DELETE FROM products WHERE status=13
DELETE FROM products WHERE status=13;
Add semicolon.
SQL
list(20)
if length(list) >= 20, list(20), end
Check length.
MATLAB
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
if ($count = 32) {{}}
if ($count -eq 32) {{}}
Use -eq.
PowerShell
status: info id: world,
status: info id: world
Remove comma.
YAML
<user><name>result</name><age>24</age></user
<user><name>result</name><age>24</age></user>
Add closing >.
XML
if ($data = 92)
if ($data == 92)
Use ==.
Perl
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
handle
handle()
Add parentheses.
Swift
if index = 32
if index == 32
Use ==.
MATLAB
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
print 'result'
print('result')
print needs parentheses.
Python
let temp: number = 'data';
let temp: string = 'data';
Fix type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
["message", 74]
["message", 74]
Correct.
JSON
if (data = 85) {{}}
if (data === 85) {{}}
Use === for equality.
JavaScript
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
compute
compute()
Add parentheses.
Kotlin
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
jwt.sign({{id:32}}, 'password');
jwt.sign({{id:32}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
String c = 'test';
String c = "test";
Double quotes.
Java
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
if (c = 16) {{}}
if (c == 16) {{}}
Use ==.
Java
INSERT INTO orders VALUES ('info',80)
INSERT INTO orders (id, status) VALUES ('info',80);
Specify columns.
SQL
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
if (z = 58)
if (z == 58)
Use ==.
C++
function foo(): void {{ return 38; }}
function foo(): number {{ return 38; }}
Return type mismatch.
TypeScript
if [ $b = 6 ]; then
if [ "$b" = 6 ]; then
Quote variable.
Shell
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
if z = 30:
if z == 30:
Use == for comparison.
Python
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let y = 'world'
let y = "world"
Double quotes.
Swift
let temp: number | null = null; temp.toFixed(13);
let temp: number | null = null; if(temp!==null) temp.toFixed(13);
Null check.
TypeScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
disp('output')
disp('output')
Correct.
MATLAB
val data = 'result'
val data = "result"
Double quotes.
Kotlin
$list[13] = 5;
if (isset($list[13])) $list[13] = 5;
Check existence.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[17, 54, 10
[17, 54, 10]
Close bracket.
Ruby
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if index > 30 print('value')
if index > 30: print('value')
Colon missing after if.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
int items[17]; items[17]=5;
int items[17]; if(17<17){{}} else items[17]=5;
Bounds check.
C++
if (data = 66)
if (data == 66)
Use ==.
R
arr[23]
if (arr.indices.contains(23)) arr[23]
Check index.
Kotlin
h1 {{ font-size:16px color:green; }}
h1 {{ font-size:16px; color:green; }}
Add semicolon.
CSS
SELECT * FROM orders WHRE id=74;
SELECT * FROM orders WHERE id=74;
Fix WHERE.
SQL
re.sqrt(44)
import re re.sqrt(44)
Import module first.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
values[4]
if values.indices.contains(4) {{ values[4] }}
Check index.
Swift
print('info')
print('info')
Correct.
R
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
assert z > 20
assert z > 20
Correct.
Python
fn foo() -> i32 {{ 63 }}
fn foo() -> i32 {{ 63 }}
Correct.
Rust
cin >> a;
int a; cin >> a;
Declare variable.
C++
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
{{'status':68, 'title' 46}}
{{'status':68, 'title':46}}
Colon missing.
Python
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function baz(x:string){{return x;}} baz(30);
function baz(x:string){{return x;}} baz('data');
Pass correct type.
TypeScript
WHERE age = '4'
WHERE age = 4
Don't quote integer.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
UPDATE users SET name='message' WHERE email=23
UPDATE users SET name='message' WHERE email=23;
Add semicolon.
SQL
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
else print('value')
else: print('value')
Colon after else.
Python
for data in range(24) print(data)
for data in range(24): print(data)
Colon after for.
Python
let num = 9;
let num = 9;
Correct.
JavaScript
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (c = 100) {{}}
if (c == 100) {{}}
Use ==.
Kotlin
if data > 96 puts 'data'
if data > 96 puts 'data' end
Add 'end'.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
[22, 56, 72
[22, 56, 72]
Close bracket.
Python
46bar = 10
bar46 = 10
Variable cannot start with digit.
Python