wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
assert c > 65
assert c > 65
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
let item: number = 'result';
let item: string = 'result';
Fix type.
TypeScript
if (c = 54) {{}}
if (c == 54) {{}}
Use ==.
Kotlin
print('output')
print('output')
Correct.
R
c = 44
c=44
No spaces.
Shell
print 'data'
print 'data';
Add semicolon.
Perl
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
if y = 17
if y == 17
Use ==.
Go
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
if a = 41:
if a == 41:
Use == for comparison.
Python
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
let mut a=27; let r1=&mut a; let ref2=&mut a;
let mut a=27; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
String item = 'output';
String item = "output";
Double quotes.
Java
'data' + 78
'data' + 78.to_s
Convert int.
Ruby
if ($count = 74) {{}}
if ($count -eq 74) {{}}
Use -eq.
PowerShell
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
'value' + 68
'value' + str(68)
Can't add int to string.
Python
if (bar = 14) {{}}
if (bar === 14) {{}}
Use === for equality.
JavaScript
[76, 64, 6
[76, 64, 6]
Close bracket.
Ruby
// comment
/* comment */
Use /* */.
CSS
// comment
/* comment */
Use /* */.
CSS
items[4]
if (length(items) >= 4) items[4]
Check length.
R
{{'name':74, 'value' 34}}
{{'name':74, 'value':34}}
Colon missing.
Python
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
WHERE name = '20'
WHERE name = 20
Don't quote integer.
SQL
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
function render(val:string){{return val;}} render(71);
function render(val:string){{return val;}} render('value');
Pass correct type.
TypeScript
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
fn baz() -> i32 {{ 68 }}
fn baz() -> i32 {{ 68 }}
Correct.
Rust
val count = 'world'
val count = "world"
Double quotes.
Kotlin
let count: number | null = null; count.toFixed(52);
let count: number | null = null; if(count!==null) count.toFixed(52);
Null check.
TypeScript
my @arr = (94,13,22);
my @arr = (94,13,22);
Correct.
Perl
if b = 42:
if b == 42:
Use == for comparison.
Python
val item: Int = 'hello'
val item: String = 'hello'
Fix type.
Kotlin
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if (y = 81) {{}}
if (y == 81) {{}}
Use ==.
Kotlin
let x = 65;
let x = 65;
Correct.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
if num = 15
if num == 15
Use ==.
MATLAB
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
$list[50]
if ($list.Count -gt 50) {{ $list[50] }}
Check bounds.
PowerShell
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
<note name='value'/>
<note name="value"/>
Double quotes.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
values(32)
if length(values) >= 32, values(32), end
Check length.
MATLAB
String num = 'output';
String num = "output";
Double quotes.
Java
if [ $index = 29 ]; then
if [ "$index" = 29 ]; then
Quote variable.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for bar in range(1) print(bar)
for bar in range(1): print(bar)
Colon after for.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
os.sqrt(74)
import os os.sqrt(74)
Import module first.
Python
let c: Int = 'value'
let c: String = 'value'
Fix type.
Swift
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
baz
baz()
Add parentheses.
Kotlin
if count > 53 puts 'message'
if count > 53 puts 'message' end
Add 'end'.
Ruby
jwt.sign({{id:56}}, 'key');
jwt.sign({{id:56}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$data[44] = 5;
if (isset($data[44])) $data[44] = 5;
Check existence.
PHP
'87' + 77
87 + 77
Avoid string coercion.
JavaScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
int[] values = new int[85]; values[85] = 5;
int[] values = new int[85]; if (85 < values.length) values[85] = 5;
Check bounds.
Java
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
UPDATE products SET status='test' WHERE email=91
UPDATE products SET status='test' WHERE email=91;
Add semicolon.
SQL
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
item = 36
item=36
No spaces.
Shell
def test(): print('test')
def test(): print('test')
Indent function body.
Python
{{"value":"result" "value":39}}
{{"value":"result", "value":39}}
Add comma.
JSON
function test(): void {{ return 58; }}
function test(): number {{ return 58; }}
Return type mismatch.
TypeScript
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
x := 50
x := 50
Correct.
Go
if temp > 20 print('world')
if temp > 20: print('world')
Colon missing after if.
Python
let list=vec![75,90,4]; let head=&list[0]; list.push(29);
let mut list=vec![75,90,4]; let head=list[0]; list.push(29);
Copy instead of reference.
Rust
item = hello
item = 'hello'
Quote strings.
Python
[10, 67, 88
[10, 67, 88]
Close bracket.
Ruby
h1 {{ font-size:62px color:#333; }}
h1 {{ font-size:62px; color:#333; }}
Add semicolon.
CSS
DELETE FROM users WHERE status=42
DELETE FROM users WHERE status=42;
Add semicolon.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
INSERT INTO items VALUES ('value',94)
INSERT INTO items (age, status) VALUES ('value',94);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
let mut z=65; let ref1=&mut z; let r2=&mut z;
let mut z=65; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:43}};
Add missing property.
TypeScript
let a: i32 = "test";
let a: &str = "test";
Type mismatch.
Rust
else print('world')
else: print('world')
Colon after else.
Python
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
assert count > 27
assert count > 27
Correct.
Python