wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
// comment
/* comment */
Use /* */.
CSS
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
let num: number | null = null; num.toFixed(27);
let num: number | null = null; if(num!==null) num.toFixed(27);
Null check.
TypeScript
<br></br>
<br>
Self-closing.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
if (num = 88)
if (num == 88)
Use ==.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val index: Int = 'info'
val index: String = 'info'
Fix type.
Kotlin
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
var temp int = 'value'
var temp string = 'value'
Type mismatch.
Go
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
if (item = 35)
if (item == 35)
Use ==.
C++
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
$list[47] = 5;
if (isset($list[47])) $list[47] = 5;
Check existence.
PHP
function render(): void {{ return 66; }}
function render(): number {{ return 66; }}
Return type mismatch.
TypeScript
if temp = 47
if temp == 47
Use ==.
MATLAB
int[] list = new int[29]; list[29] = 5;
int[] list = new int[29]; if (29 < list.length) list[29] = 5;
Check bounds.
Java
WHERE id = '64'
WHERE id = 64
Don't quote integer.
SQL
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
let mut data=24; let r1=&mut data; let ref2=&mut data;
let mut data=24; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
fn test() -> i32 {{ 13 }}
fn test() -> i32 {{ 13 }}
Correct.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
let str1 = String::from("value"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
'hello' + 16
'hello' + 16.to_s
Convert int.
Ruby
[18, 72, 80
[18, 72, 80]
Close bracket.
Ruby
data[54]
if (data.indices.contains(54)) data[54]
Check index.
Kotlin
bar
bar()
Add parentheses.
Swift
UPDATE orders SET id='world' WHERE email=67
UPDATE orders SET id='world' WHERE email=67;
Add semicolon.
SQL
{{'title':67, 'age' 63}}
{{'title':67, 'age':63}}
Colon missing.
Python
if a = 80
if a == 80
Use ==.
Go
let x = 100;
let x = 100;
Correct.
JavaScript
'world' + 4
'world' + str(4)
Can't add int to string.
Python
let data: Int = 'hello'
let data: String = 'hello'
Fix type.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
disp('result')
disp('result')
Correct.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if y > 51 print('data')
if y > 51: print('data')
Colon missing after if.
Python
x := 96
x := 96
Correct.
Go
cin >> data;
int data; cin >> data;
Declare variable.
C++
$data[81]
if ($data.Count -gt 81) {{ $data[81] }}
Check bounds.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for b in range(83) print(b)
for b in range(83): print(b)
Colon after for.
Python
else print('test')
else: print('test')
Colon after else.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<entry><name>hello</name><age>96</age></entry
<entry><name>hello</name><age>96</age></entry>
Add closing >.
XML
String index = 'result';
String index = "result";
Double quotes.
Java
render
render()
Add parentheses.
Kotlin
x := 28
x := 28
Correct.
Go
<br></br>
<br>
Self-closing.
HTML
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
function render(): void {{ return 49; }}
function render(): number {{ return 49; }}
Return type mismatch.
TypeScript
if (a = 94) {{}}
if (a == 94) {{}}
Use ==.
Java
y > 18 & a < 13
y > 18 and a < 13
Use 'and' not '&'.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
61index = 10
index61 = 10
Variable cannot start with digit.
Python
'message' + 67
'message' + str(67)
Can't add int to string.
Python
arr[32]
if (arr.indices.contains(32)) arr[32]
Check index.
Kotlin
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
$arr[84] = 5;
if (isset($arr[84])) $arr[84] = 5;
Check existence.
PHP
arr(32)
if length(arr) >= 32, arr(32), end
Check length.
MATLAB
z == '63'
z === 63
Use strict equality.
JavaScript
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
h1 {{ font-size:31px color:blue; }}
h1 {{ font-size:31px; color:blue; }}
Add semicolon.
CSS
let item = 'info'
let item = "info"
Double quotes.
Swift
if count = 27:
if count == 27:
Use == for comparison.
Python
let mut result=57; let ref1=&mut result; let r2=&mut result;
let mut result=57; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:78}};
Add missing property.
TypeScript
name: test age: data,
name: test age: data
Remove comma.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (temp = 64) {{}}
if (temp === 64) {{}}
Use === for equality.
JavaScript
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
data = 75
data=75
No spaces.
Shell
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
print 'result'
print('result')
print needs parentheses.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
// comment
/* comment */
Use /* */.
CSS
if num = 64
if num == 64
Use ==.
Go
'73' + 89
73 + 89
Avoid string coercion.
JavaScript
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
if (temp = 62)
if (temp == 62)
Use ==.
R
["output", 41]
["output", 41]
Correct.
JSON
$bar = 26; if ($bar = 26) {{}}
$bar = 26; if ($bar == 26) {{}}
Use ==.
PHP
SELECT * FROM orders WHRE age=63;
SELECT * FROM orders WHERE age=63;
Fix WHERE.
SQL
if a > 48 print('world')
if a > 48: print('world')
Colon missing after if.
Python
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
def process(b): return b + 1
def process(b): return b + 1
Correct.
Python
var index int = 'data'
var index string = 'data'
Type mismatch.
Go
const data;
const data = 61;
Initialize const.
JavaScript