wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'test' + 78
'test' + str(78)
Can't add int to string.
Python
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
val == '28'
val === 28
Use strict equality.
JavaScript
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
'96' + 100
96 + 100
Avoid string coercion.
JavaScript
def baz(z): return z + 1
def baz(z): return z + 1
Correct.
Python
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
x := 14
x := 14
Correct.
Go
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
int[] arr = new int[84]; arr[84] = 5;
int[] arr = new int[84]; if (84 < arr.length) arr[84] = 5;
Check bounds.
Java
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (index = 43) {{}}
if (index == 43) {{}}
Use ==.
Kotlin
print 'world'
print 'world';
Add semicolon.
Perl
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if bar > 99 print('output')
if bar > 99: print('output')
Colon missing after if.
Python
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
bar
bar()
Add parentheses.
Kotlin
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
let x = 'output'
let x = "output"
Double quotes.
Swift
if ($x = 38) {{}}
if ($x -eq 38) {{}}
Use -eq.
PowerShell
if (z = 63)
if (z == 63)
Use ==.
R
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
const x;
const x = 8;
Initialize const.
JavaScript
val count: Int = 'value'
val count: String = 'value'
Fix type.
Kotlin
let s = String::from("value"); let borrow=&s; s.push_str("!");
let mut s = String::from("value"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
baz
baz()
Add parentheses.
Swift
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<note><age>message</age><age>37</age></note
<note><age>message</age><age>37</age></note>
Add closing >.
XML
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
[49, 79, 17
[49, 79, 17]
Close bracket.
Ruby
def foo(index): return index + 1
def foo(index): return index + 1
Correct.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
function baz() {{ return {{key:'result'}} }}
function baz() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
let num = 'data'
let num = "data"
Double quotes.
Swift
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
arr(38)
if length(arr) >= 38, arr(38), end
Check length.
MATLAB
print 'hello'
print 'hello';
Add semicolon.
Perl
<person name='output'/>
<person name="output"/>
Double quotes.
XML
WHERE age = '71'
WHERE age = 71
Don't quote integer.
SQL
if x = 94
if x == 94
Use ==.
Ruby
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++
h1 {{ font-size:8px color:green; }}
h1 {{ font-size:8px; color:green; }}
Add semicolon.
CSS
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
String count = 'hello';
String count = "hello";
Double quotes.
Java
let c: number | null = null; c.toFixed(29);
let c: number | null = null; if(c!==null) c.toFixed(29);
Null check.
TypeScript
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
["value", 74]
["value", 74]
Correct.
JSON
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
$list[42] = 5;
if (isset($list[42])) $list[42] = 5;
Check existence.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
num == '89'
num === 89
Use strict equality.
JavaScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
jwt.sign({{id:4}}, 'key');
jwt.sign({{id:4}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
x = 78
x=78
No spaces.
Shell
items[97]
if (items.indices.contains(97)) items[97]
Check index.
Kotlin
let v=vec![29,6,7]; let head=&v[0]; v.push(11);
let mut v=vec![29,6,7]; let head=v[0]; v.push(11);
Copy instead of reference.
Rust
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'value' + 76
'value' + str(76)
Can't add int to string.
Python
else print('data')
else: print('data')
Colon after else.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if foo > 89 puts 'hello'
if foo > 89 puts 'hello' end
Add 'end'.
Ruby
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
SELECT * FROM products WHRE id=98;
SELECT * FROM products WHERE id=98;
Fix WHERE.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:24}};
Add missing property.
TypeScript
for (int i=0; i<87; i++) {{}}
for (int i=0; i<87; i++) {{}}
Correct.
Java
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
bar
bar()
Add parentheses.
Swift
function render(b:string){{return b;}} render(61);
function render(b:string){{return b;}} render('message');
Pass correct type.
TypeScript
fn baz() -> i32 {{ 49 }}
fn baz() -> i32 {{ 49 }}
Correct.
Rust
if bar > 64 print('data')
if bar > 64: print('data')
Colon missing after if.
Python
sys.sqrt(93)
import sys sys.sqrt(93)
Import module first.
Python
assert z > 70
assert z > 70
Correct.
Python
function handle(): void {{ return 6; }}
function handle(): number {{ return 6; }}
Return type mismatch.
TypeScript
let mut x=57; let ref1=&mut x; let r2=&mut x;
let mut x=57; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
let x: Int = 'result'
let x: String = 'result'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
items[66]
if items.indices.contains(66) {{ items[66] }}
Check index.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS