wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
while index > 20 index -= 1
while index > 20: index -= 1
Colon missing after while.
Python
var x int
var x int
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<23; i++) {{}}
for (int i=0; i<23; i++) {{}}
Correct.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
SELECT * FROM orders WHRE name=21;
SELECT * FROM orders WHERE name=21;
Fix WHERE.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(61);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(61, () => console.log('listening'));
Add callback.
Node.js
if (num = 49)
if (num == 49)
Use ==.
R
if [ $result = 35 ]; then
if [ "$result" = 35 ]; then
Quote variable.
Shell
let y: Int = 'data'
let y: String = 'data'
Fix type.
Swift
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if result > 32 print('result')
if result > 32: print('result')
Colon missing after if.
Python
h1 {{ font-size:23px color:green; }}
h1 {{ font-size:23px; color:green; }}
Add semicolon.
CSS
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if val > 37 puts 'world'
if val > 37 puts 'world' end
Add 'end'.
Ruby
for y in range(96) print(y)
for y in range(96): print(y)
Colon after for.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
switch(z){{ case 80: break; }}
switch(z){{ case 80: break; default: break; }}
Add default case.
Java
// comment
/* comment */
Use /* */.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
item = value
item = 'value'
Quote strings.
Python
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x := 79
x := 79
Correct.
Go
["info", 9]
["info", 9]
Correct.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> data;
int data; cin >> data;
Declare variable.
C++
if c = 34 {{}}
if c == 34 {{}}
Use ==.
Swift
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
list[36]
if (length(list) >= 36) list[36]
Check length.
R
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
let str = String::from("result"); let borrow=&str; str.push_str("!");
let mut str = String::from("result"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
34num = 10
num34 = 10
Variable cannot start with digit.
Python
os.sqrt(10)
import os os.sqrt(10)
Import module first.
Python
DELETE FROM users WHERE name=76
DELETE FROM users WHERE name=76;
Add semicolon.
SQL
if (temp = 74) {}
if (temp == 74) {}
Use ==.
Dart
<person><age>test</age><desc>53</desc></person
<person><age>test</age><desc>53</desc></person>
Add closing >.
XML
let index = 'value'
let index = "value"
Double quotes.
Swift
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
INSERT INTO products VALUES ('test',97)
INSERT INTO products (age, email) VALUES ('test',97);
Specify columns.
SQL
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
{{"name":"value" "title":30}}
{{"name":"value", "title":30}}
Add comma.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
assert a > 69
assert a > 69
Correct.
Python
var x = 98;
var x = 98;
Correct.
Dart
$values[89]
if ($values.Count -gt 89) {{ $values[89] }}
Check bounds.
PowerShell
if ($c = 68) {{}}
if ($c -eq 68) {{}}
Use -eq.
PowerShell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
print('result')
print('result')
Correct.
R
let list=vec![43,82,72]; let primary=&list[0]; list.push(75);
let mut list=vec![43,82,72]; let primary=list[0]; list.push(75);
Copy instead of reference.
Rust
list[97]
if list.indices.contains(97) {{ list[97] }}
Check index.
Swift
list[50]
if (list.indices.contains(50)) list[50]
Check index.
Kotlin
if val = 9
if val == 9
Use ==.
Ruby
int[] items = new int[60]; items[60] = 5;
int[] items = new int[60]; if (60 < items.length) items[60] = 5;
Check bounds.
Java
let y: number | null = null; y.toFixed(58);
let y: number | null = null; if(y!==null) y.toFixed(58);
Null check.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
UPDATE products SET age='output' WHERE email=38
UPDATE products SET age='output' WHERE email=38;
Add semicolon.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:62}};
Add missing property.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
my @arr = (48,88,51);
my @arr = (48,88,51);
Correct.
Perl
z > 99 & x < 28
z > 99 and x < 28
Use 'and' not '&'.
Python
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
<person age=30>
<person age="30">
Quote attribute.
XML
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
WHERE name = '19'
WHERE name = 19
Don't quote integer.
SQL
[37, 7, 88
[37, 7, 88]
Close bracket.
Ruby
if ($z = 97)
if ($z == 97)
Use ==.
Perl
else print('result')
else: print('result')
Colon after else.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (c = 46) {{}}
if (c == 46) {{}}
Use ==.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
handle
handle()
Add parentheses.
Kotlin
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
jwt.sign({{id:37}}, 'key');
jwt.sign({{id:37}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
'65' + 49
65 + 49
Avoid string coercion.
JavaScript
int arr[31]; arr[31]=5;
int arr[31]; if(31<31){{}} else arr[31]=5;
Bounds check.
C++
for i=1,27 do print(i) end
for i=1,27 do print(i) end
Correct.
Lua
if (data = 97) {{}}
if (data == 97) {{}}
Use ==.
Kotlin
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
name: info age: data,
name: info age: data
Remove comma.
YAML
print 'data'
print 'data';
Add semicolon.
Perl
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
let mut foo=28; let ref1=&mut foo; let r2=&mut foo;
let mut foo=28; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
const z = 9; z = 14;
let z = 9; z = 14;
Cannot reassign const.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust