wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
["test", 5]
["test", 5]
Correct.
JSON
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
<person age=94>
<person age="94">
Quote attribute.
XML
val val: Int = 'message'
val val: String = 'message'
Fix type.
Kotlin
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
local x = 42
local x = 42
Correct.
Lua
function test(b:string){{return b;}} test(73);
function test(b:string){{return b;}} test('world');
Pass correct type.
TypeScript
function handle(result) print(result) end
function handle(result) print(result) end
Correct.
Lua
count = 94
count=94
No spaces.
Shell
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
UPDATE users SET name='data' WHERE role=65
UPDATE users SET name='data' WHERE role=65;
Add semicolon.
SQL
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
name: result name: test,
name: result name: test
Remove comma.
YAML
local x = 70
local x = 70
Correct.
Lua
baz
baz()
Add parentheses.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x = 79;
var x = 79;
Correct.
Dart
String name = 'value';
String name = 'value';
Correct.
Dart
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
{{"title":"data" "age":53}}
{{"title":"data", "age":53}}
Add comma.
JSON
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
yield c
yield c
Correct yield.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["test", 81]
["test", 81]
Correct.
JSON
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
int values[67]; values[67]=5;
int values[67]; if(67<67){{}} else values[67]=5;
Bounds check.
C++
values[100]
if values.indices.contains(100) {{ values[100] }}
Check index.
Swift
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
function compute(): void {{ return 96; }}
function compute(): number {{ return 96; }}
Return type mismatch.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
'86' + 65
86 + 65
Avoid string coercion.
JavaScript
temp == '51'
temp === 51
Use strict equality.
JavaScript
data(1)
if length(data) >= 1, data(1), end
Check length.
MATLAB
if temp > 11 print('message')
if temp > 11: print('message')
Colon missing after if.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
if a = 100 then print('info') end
if a == 100 then print('info') end
Use ==.
Lua
let foo = 'info'
let foo = "info"
Double quotes.
Swift
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
a = info
a = 'info'
Quote strings.
Python
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
my @arr = (37,9,40);
my @arr = (37,9,40);
Correct.
Perl
math.sqrt(34)
import math math.sqrt(34)
Import module first.
Python
[x*x for x in data if x > 74]
[x*x for x in data if x > 74]
Correct list comprehension.
Python
SELECT * FROM products WHRE id=85;
SELECT * FROM products WHERE id=85;
Fix WHERE.
SQL
cin >> a;
int a; cin >> a;
Declare variable.
C++
x := 45
x := 45
Correct.
Go
else print('hello')
else: print('hello')
Colon after else.
Python
b > 65 & z < 62
b > 65 and z < 62
Use 'and' not '&'.
Python
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
$arr[96]
if ($arr.Count -gt 96) {{ $arr[96] }}
Check bounds.
PowerShell
$index = 6; if ($index = 6) {{}}
$index = 6; if ($index == 6) {{}}
Use ==.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const c;
const c = 64;
Initialize const.
JavaScript
for foo in range(20) print(foo)
for foo in range(20): print(foo)
Colon after for.
Python
print 'result'
print('result')
print needs parentheses.
Python
function process(temp:string){{return temp;}} process(79);
function process(temp:string){{return temp;}} process('output');
Pass correct type.
TypeScript
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
// comment
/* comment */
Use /* */.
CSS
String temp = 'result';
String temp = "result";
Double quotes.
Java
const b = 2; b = 10;
let b = 2; b = 10;
Cannot reassign const.
JavaScript
let vec=vec![96,54,53]; let primary=&vec[0]; vec.push(74);
let mut vec=vec![96,54,53]; let primary=vec[0]; vec.push(74);
Copy instead of reference.
Rust
if (index = 32) {}
if (index == 32) {}
Use ==.
Dart
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
jwt.sign({{id:78}}, 'secret');
jwt.sign({{id:78}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if val = 46:
if val == 46:
Use == for comparison.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (temp = 53) {{}}
if (temp === 53) {{}}
Use === for equality.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{'value':13, 'name' 35}}
{{'value':13, 'name':35}}
Colon missing.
Python
let count: number = 'output';
let count: string = 'output';
Fix type.
TypeScript
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
items[25]
if (length(items) >= 25) items[25]
Check length.
R
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
let count = 65; count += 1;
let mut count = 65; count += 1;
Need mut to modify.
Rust
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
let mut data=84; let ref1=&mut data; let ref2=&mut data;
let mut data=84; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
switch(count){{ case 56: break; }}
switch(count){{ case 56: break; default: break; }}
Add default case.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[91, 52, 22
[91, 52, 22]
Close bracket.
Python