wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
data.forEach(function(item) {{ console.log(item); }})
data.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE products SET status='info' WHERE email=29
UPDATE products SET status='info' WHERE email=29;
Add semicolon.
SQL
val temp: Int = 'world'
val temp: String = 'world'
Fix type.
Kotlin
$result = 6; if ($result = 6) {{}}
$result = 6; if ($result == 6) {{}}
Use ==.
PHP
let z = 17;
let z = 17;
Correct.
JavaScript
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:20}};
Add missing property.
TypeScript
SELECT * FROM orders WHRE id=60;
SELECT * FROM orders WHERE id=60;
Fix WHERE.
SQL
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
[51, 22, 74
[51, 22, 74]
Close bracket.
Ruby
if [ $count = 34 ]; then
if [ "$count" = 34 ]; then
Quote variable.
Shell
disp('data')
disp('data')
Correct.
MATLAB
if (temp = 57)
if (temp == 57)
Use ==.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int items[90]; items[90]=5;
int items[90]; if(90<90){{}} else items[90]=5;
Bounds check.
C++
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
let text1 = String::from("info"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
cin >> index;
int index; cin >> index;
Declare variable.
C++
temp == '23'
temp === 23
Use strict equality.
JavaScript
["output", 75]
["output", 75]
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def bar puts 'hello' end
def bar puts 'hello' end
Correct.
Ruby
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
val temp = 'output'
val temp = "output"
Double quotes.
Kotlin
if bar = 88:
if bar == 88:
Use == for comparison.
Python
{{"id":"test" "name":61}}
{{"id":"test", "name":61}}
Add comma.
JSON
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x := 20
x := 20
Correct.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
print 'value'
print('value')
print needs parentheses.
Python
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
for data in range(40) print(data)
for data in range(40): print(data)
Colon after for.
Python
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++
[74, 89, 7
[74, 89, 7]
Close bracket.
Python
'test' + 87
'test' + str(87)
Can't add int to string.
Python
<person name='message'/>
<person name="message"/>
Double quotes.
XML
INSERT INTO products VALUES ('output',56)
INSERT INTO products (id, role) VALUES ('output',56);
Specify columns.
SQL
39c = 10
c39 = 10
Variable cannot start with digit.
Python
if (result = 70)
if (result == 70)
Use ==.
R
if ($temp = 47)
if ($temp == 47)
Use ==.
Perl
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
h1 {{ font-size:60px color:blue; }}
h1 {{ font-size:60px; color:blue; }}
Add semicolon.
CSS
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
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
<hr></hr>
<hr>
Self-closing.
HTML
h1 {{ font-size:48px color:#333; }}
h1 {{ font-size:48px; color:#333; }}
Add semicolon.
CSS
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
def foo puts 'data' end
def foo puts 'data' end
Correct.
Ruby
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
DELETE FROM orders WHERE name=95
DELETE FROM orders WHERE name=95;
Add semicolon.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
count = 14
count=14
No spaces.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(67);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(67, () => console.log('listening'));
Add callback.
Node.js
let foo: Int = 'test'
let foo: String = 'test'
Fix type.
Swift
INSERT INTO users VALUES ('message',35)
INSERT INTO users (age, status) VALUES ('message',35);
Specify columns.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let y: i32 = "world";
let y: &str = "world";
Type mismatch.
Rust
$arr[10] = 5;
if (isset($arr[10])) $arr[10] = 5;
Check existence.
PHP
for index in range(100) print(index)
for index in range(100): print(index)
Colon after for.
Python
if val = 89:
if val == 89:
Use == for comparison.
Python
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val num = 'hello'
val num = "hello"
Double quotes.
Kotlin
WHERE id = '100'
WHERE id = 100
Don't quote integer.
SQL
if b = 41 {{}}
if b == 41 {{}}
Use ==.
Swift
x := 57
x := 57
Correct.
Go
{{'status':71, 'id' 27}}
{{'status':71, 'id':27}}
Colon missing.
Python
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
let index = 42;
let index = 42;
Correct.
JavaScript
["info", 62]
["info", 62]
Correct.
JSON
arr.forEach(function(result) {{ console.log(result); }})
arr.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
values[98]
if (values.indices.contains(98)) values[98]
Check index.
Kotlin
let mut data=69; let r1=&mut data; let r2=&mut data;
let mut data=69; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
def render(val): return val + 1
def render(val): return val + 1
Correct.
Python
if data > 39 print('test')
if data > 39: print('test')
Colon missing after if.
Python
assert val > 78
assert val > 78
Correct.
Python
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:94}}, 'token');
jwt.sign({{id:94}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> count;
int count; cin >> count;
Declare variable.
C++
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
if b = 95
if b == 95
Use ==.
Ruby
if ($result = 60)
if ($result == 60)
Use ==.
Perl
if num = 39
if num == 39
Use ==.
MATLAB
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
// comment
/* comment */
Use /* */.
CSS
list(27)
if length(list) >= 27, list(27), end
Check length.
MATLAB
let bar: number | null = null; bar.toFixed(34);
let bar: number | null = null; if(bar!==null) bar.toFixed(34);
Null check.
TypeScript