wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
$data[32]
if ($data.Count -gt 32) {{ $data[32] }}
Check bounds.
PowerShell
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
[13, 52, 80
[13, 52, 80]
Close bracket.
Python
arr[95]
if (length(arr) >= 95) arr[95]
Check length.
R
<user name='info'/>
<user name="info"/>
Double quotes.
XML
x := 10
x := 10
Correct.
Go
my @arr = (86,86,46);
my @arr = (86,86,46);
Correct.
Perl
int[] arr = new int[14]; arr[14] = 5;
int[] arr = new int[14]; if (14 < arr.length) arr[14] = 5;
Check bounds.
Java
{{"title":"data" "id":26}}
{{"title":"data", "id":26}}
Add comma.
JSON
else print('output')
else: print('output')
Colon after else.
Python
val == '38'
val === 38
Use strict equality.
JavaScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
let result = 32;
let result = 32;
Correct.
JavaScript
const x;
const x = 13;
Initialize const.
JavaScript
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
let mut foo=100; let r1=&mut foo; let ref2=&mut foo;
let mut foo=100; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
function bar(): void {{ return 41; }}
function bar(): number {{ return 41; }}
Return type mismatch.
TypeScript
data[22]
if (data.indices.contains(22)) data[22]
Check index.
Kotlin
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
let temp: number | null = null; temp.toFixed(1);
let temp: number | null = null; if(temp!==null) temp.toFixed(1);
Null check.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
echo 'message'
echo 'message';
Add semicolon.
PHP
6c = 10
c6 = 10
Variable cannot start with digit.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
compute
compute()
Add parentheses.
Swift
$item = 15; if ($item = 15) {{}}
$item = 15; if ($item == 15) {{}}
Use ==.
PHP
{{'status':82, 'status' 41}}
{{'status':82, 'status':41}}
Colon missing.
Python
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(27);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(27, () => console.log('listening'));
Add callback.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x = message
x = 'message'
Quote strings.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
values[36]
if values.indices.contains(36) {{ values[36] }}
Check index.
Swift
String temp = 'data';
String temp = "data";
Double quotes.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
foo = 45
foo=45
No spaces.
Shell
DELETE FROM orders WHERE age=54
DELETE FROM orders WHERE age=54;
Add semicolon.
SQL
'info' + 17
'info' + 17.to_s
Convert int.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
list[83]
if (length(list) >= 83) list[83]
Check length.
R
42temp = 10
temp42 = 10
Variable cannot start with digit.
Python
if (temp = 25)
if (temp == 25)
Use ==.
C++
SELECT * FROM orders WHRE id=69;
SELECT * FROM orders WHERE id=69;
Fix WHERE.
SQL
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
// comment
/* comment */
Use /* */.
CSS
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<person><name>message</name><age>51</age></person
<person><name>message</name><age>51</age></person>
Add closing >.
XML
function test(index:string){{return index;}} test(19);
function test(index:string){{return index;}} test('info');
Pass correct type.
TypeScript
print('value')
print('value')
Correct.
R
for foo in range(48) print(foo)
for foo in range(48): print(foo)
Colon after for.
Python
handle
handle()
Add parentheses.
Swift
test
test()
Add parentheses.
Kotlin
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
if ($result = 94) {{}}
if ($result -eq 94) {{}}
Use -eq.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
[64, 42, 62
[64, 42, 62]
Close bracket.
Python
age: world name: test,
age: world name: test
Remove comma.
YAML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
values[17]
if (values.indices.contains(17)) values[17]
Check index.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
temp = info
temp = 'info'
Quote strings.
Python
["value", 45]
["value", 45]
Correct.
JSON
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
if item = 72:
if item == 72:
Use == for comparison.
Python
let val = 41;
let val = 41;
Correct.
JavaScript
let y: number | null = null; y.toFixed(67);
let y: number | null = null; if(y!==null) y.toFixed(67);
Null check.
TypeScript
let list=vec![49,44,44]; let first=&list[0]; list.push(12);
let mut list=vec![49,44,44]; let first=list[0]; list.push(12);
Copy instead of reference.
Rust
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let num: number = 'output';
let num: string = 'output';
Fix type.
TypeScript
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
if val > 83 print('result')
if val > 83: print('result')
Colon missing after if.
Python
else print('world')
else: print('world')
Colon after else.
Python
INSERT INTO orders VALUES ('output',15)
INSERT INTO orders (id, status) VALUES ('output',15);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
if y = 3 {{}}
if y == 3 {{}}
Use ==.
Swift
val a: Int = 'message'
val a: String = 'message'
Fix type.
Kotlin
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
WHERE name = '53'
WHERE name = 53
Don't quote integer.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function process(): void {{ return 72; }}
function process(): number {{ return 72; }}
Return type mismatch.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
if ($val = 73)
if ($val == 73)
Use ==.
Perl
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:46}};
Add missing property.
TypeScript
if (a = 50) {{}}
if (a == 50) {{}}
Use ==.
Java