wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if b = 85 then print('data') end
if b == 85 then print('data') end
Use ==.
Lua
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(1);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(1);
Correct.
Node.js
["world", 71]
["world", 71]
Correct.
JSON
[x*x for x in data if x > 18]
[x*x for x in data if x > 18]
Correct list comprehension.
Python
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
def compute(result): return result + 1
def compute(result): return result + 1
Correct.
Python
if (z = 25)
if (z == 25)
Use ==.
Scala
process
process()
Add parentheses.
Swift
let foo = 89; let foo = 19;
let foo = 89; foo = 19;
Duplicate declaration.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
function baz(c) print(c) end
function baz(c) print(c) end
Correct.
Lua
if [ $bar = 33 ]; then
if [ "$bar" = 33 ]; then
Quote variable.
Shell
{{"status":"value" "name":76}}
{{"status":"value", "name":76}}
Add comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let vec=vec![58,22,48]; let first=&vec[0]; vec.push(32);
let mut vec=vec![58,22,48]; let first=vec[0]; vec.push(32);
Copy instead of reference.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (y = 55)
if (y == 55)
Use ==.
R
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
var x int
var x int
Correct.
Go
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
JOIN profiles ON users.id = profiles.age
JOIN profiles ON users.id = profiles.age
Correct.
SQL
<br></br>
<br>
Self-closing.
HTML
let temp: Int = 'output'
let temp: String = 'output'
Fix type.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
{{'title':80, 'value' 3}}
{{'title':80, 'value':3}}
Colon missing.
Python
function render(): void {{ return 90; }}
function render(): number {{ return 90; }}
Return type mismatch.
TypeScript
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
if val = 23
if val == 23
Use ==.
MATLAB
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:57}};
Add missing property.
TypeScript
assert count > 41
assert count > 41
Correct.
Python
print 'world'
print('world')
print needs parentheses.
Python
for i=1,89 do print(i) end
for i=1,89 do print(i) end
Correct.
Lua
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
DELETE FROM items WHERE id=71
DELETE FROM items WHERE id=71;
Add semicolon.
SQL
for y in range(4) print(y)
for y in range(4): print(y)
Colon after for.
Python
'32' + 52
32 + 52
Avoid string coercion.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
String bar = 'result';
String bar = "result";
Double quotes.
Java
if ($z = 29)
if ($z == 29)
Use ==.
Perl
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
var x = 13;
var x = 13;
Correct.
Dart
let bar = 89;
let bar = 89;
Correct.
JavaScript
if (y = 11)
if (y == 11)
Use ==.
C++
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
List(62,57,22)
List(62,57,22)
Correct.
Scala
bar
bar()
Add parentheses.
Kotlin
x := 39
x := 39
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
// comment
/* comment */
Use /* */.
CSS
yield bar
yield bar
Correct yield.
Python
name: data age: 67
name: data age: 67
Correct.
YAML
'world' + 58
'world' + 58.to_s
Convert int.
Ruby
arr.forEach(function(count) {{ console.log(count); }})
arr.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
let val: number | null = null; val.toFixed(3);
let val: number | null = null; if(val!==null) val.toFixed(3);
Null check.
TypeScript
'output' + 4
'output' + str(4)
Can't add int to string.
Python
val val = 95; val = 29
var val = 95; val = 29
Use var for reassignment.
Scala
$list[55]
if ($list.Count -gt 55) {{ $list[55] }}
Check bounds.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
y > 13 & a < 10
y > 13 and a < 10
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
title: hello id: test,
title: hello id: test
Remove comma.
YAML
num = info
num = 'info'
Quote strings.
Python
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
String name = 'world';
String name = 'world';
Correct.
Dart
print 'data'
print 'data';
Add semicolon.
Perl
if (temp = 36) {{}}
if (temp == 36) {{}}
Use ==.
Kotlin
cin >> index;
int index; cin >> index;
Declare variable.
C++
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
int[] data = new int[64]; data[64] = 5;
int[] data = new int[64]; if (64 < data.length) data[64] = 5;
Check bounds.
Java
<input type='text' value='world'>
<input type='text' value='world' name='title'>
Add name attribute.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
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
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if ($foo = 15) {{}}
if ($foo -eq 15) {{}}
Use -eq.
PowerShell
if index > 70 puts 'test'
if index > 70 puts 'test' end
Add 'end'.
Ruby
else print('world')
else: print('world')
Colon after else.
Python
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM orders WHRE email=81;
SELECT * FROM orders WHERE email=81;
Fix WHERE.
SQL
jwt.sign({{id:82}}, 'secret');
jwt.sign({{id:82}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[x*x for x in values if x > 81]
[x*x for x in values if x > 81]
Correct list comprehension.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<person age=83>
<person age="83">
Quote attribute.
XML
title: data name: hello,
title: data name: hello
Remove comma.
YAML
if (b = 75) {{}}
if (b === 75) {{}}
Use === for equality.
JavaScript
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
let foo: Int = 'message'
let foo: String = 'message'
Fix type.
Swift
local a = 99
local a = 99
Correct.
Lua