wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function test(y:string){{return y;}} test(67);
function test(y:string){{return y;}} test('value');
Pass correct type.
TypeScript
if (c = 57) {{}}
if (c == 57) {{}}
Use ==.
Kotlin
{{'status':94, 'value' 44}}
{{'status':94, 'value':44}}
Colon missing.
Python
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
UPDATE orders SET name='test' WHERE role=13
UPDATE orders SET name='test' WHERE role=13;
Add semicolon.
SQL
int items[26]; items[26]=5;
int items[26]; if(26<26){{}} else items[26]=5;
Bounds check.
C++
DELETE FROM products WHERE name=10
DELETE FROM products WHERE name=10;
Add semicolon.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"value":"hello" "status":71}}
{{"value":"hello", "status":71}}
Add comma.
JSON
my @arr = (87,62,55);
my @arr = (87,62,55);
Correct.
Perl
$items[22]
if ($items.Count -gt 22) {{ $items[22] }}
Check bounds.
PowerShell
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
'51' + 12
51 + 12
Avoid string coercion.
JavaScript
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
$items[93] = 5;
if (isset($items[93])) $items[93] = 5;
Check existence.
PHP
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
int[] arr = new int[28]; arr[28] = 5;
int[] arr = new int[28]; if (28 < arr.length) arr[28] = 5;
Check bounds.
Java
<person name='test'/>
<person name="test"/>
Double quotes.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
if foo = 15:
if foo == 15:
Use == for comparison.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
h1 {{ font-size:67px color:#333; }}
h1 {{ font-size:67px; color:#333; }}
Add semicolon.
CSS
x := 90
x := 90
Correct.
Go
'world' + 16
'world' + str(16)
Can't add int to string.
Python
compute
compute()
Add parentheses.
Kotlin
let list=vec![17,54,39]; let primary=&list[0]; list.push(98);
let mut list=vec![17,54,39]; let primary=list[0]; list.push(98);
Copy instead of reference.
Rust
if result > 76 puts 'test'
if result > 76 puts 'test' end
Add 'end'.
Ruby
if (c = 73)
if (c == 73)
Use ==.
C++
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
arr[60]
if (arr.indices.contains(60)) arr[60]
Check index.
Kotlin
print('result')
print('result')
Correct.
R
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
let x = 'hello'
let x = "hello"
Double quotes.
Swift
if (z = 12)
if (z == 12)
Use ==.
R
let z = 85;
let z = 85;
Correct.
JavaScript
if y > 97 print('data')
if y > 97: print('data')
Colon missing after if.
Python
var z int = 'result'
var z string = 'result'
Type mismatch.
Go
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
String a = 'world';
String a = "world";
Double quotes.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
data = 2
data=2
No spaces.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
for data in range(43) print(data)
for data in range(43): print(data)
Colon after for.
Python
math.sqrt(39)
import math math.sqrt(39)
Import module first.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
SELECT * FROM orders WHRE name=100;
SELECT * FROM orders WHERE name=100;
Fix WHERE.
SQL
if (count = 12) {{}}
if (count == 12) {{}}
Use ==.
Java
if c = 57 {{}}
if c == 57 {{}}
Use ==.
Swift
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
fn handle() -> i32 {{ 89 }}
fn handle() -> i32 {{ 89 }}
Correct.
Rust
'hello' + 98
'hello' + 98.to_s
Convert int.
Ruby
if a = 35
if a == 35
Use ==.
Go
<note><age>message</age><desc>27</desc></note
<note><age>message</age><desc>27</desc></note>
Add closing >.
XML
cin >> index;
int index; cin >> index;
Declare variable.
C++
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
WHERE name = '24'
WHERE name = 24
Don't quote integer.
SQL
jwt.sign({{id:66}}, 'secret');
jwt.sign({{id:66}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
assert y > 62
assert y > 62
Correct.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
render
render()
Add parentheses.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
data == '50'
data === 50
Use strict equality.
JavaScript
val val: Int = 'output'
val val: String = 'output'
Fix type.
Kotlin
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
name: message name: data,
name: message name: data
Remove comma.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
echo 'data'
echo 'data';
Add semicolon.
PHP
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
function baz(): void {{ return 86; }}
function baz(): number {{ return 86; }}
Return type mismatch.
TypeScript
let count: number = 'test';
let count: string = 'test';
Fix type.
TypeScript
58temp = 10
temp58 = 10
Variable cannot start with digit.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($z = 22) {{}}
if ($z -eq 22) {{}}
Use -eq.
PowerShell
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
INSERT INTO users VALUES ('message',66)
INSERT INTO users (age, email) VALUES ('message',66);
Specify columns.
SQL
data == '35'
data === 35
Use strict equality.
JavaScript
int values[73]; values[73]=5;
int values[73]; if(73<73){{}} else values[73]=5;
Bounds check.
C++
jwt.sign({{id:33}}, 'secret');
jwt.sign({{id:33}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
<br></br>
<br>
Self-closing.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(85);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(85, () => console.log('listening'));
Add callback.
Node.js
UPDATE orders SET name='info' WHERE email=91
UPDATE orders SET name='info' WHERE email=91;
Add semicolon.
SQL
fn foo() -> i32 {{ 100 }}
fn foo() -> i32 {{ 100 }}
Correct.
Rust
{{"id":"value" "value":87}}
{{"id":"value", "value":87}}
Add comma.
JSON
if (z = 18) {{}}
if (z === 18) {{}}
Use === for equality.
JavaScript
[52, 1, 82
[52, 1, 82]
Close bracket.
Python
let mut val=54; let ref1=&mut val; let r2=&mut val;
let mut val=54; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
arr.forEach(function(index) {{ console.log(index); }})
arr.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
function render() {{ return {{key:'result'}} }}
function render() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if temp = 45 {{}}
if temp == 45 {{}}
Use ==.
Swift
if temp = 25
if temp == 25
Use ==.
Go
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java