wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
jwt.sign({{id:62}}, 'key');
jwt.sign({{id:62}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const count;
const count = 38;
Initialize const.
JavaScript
let result = 100;
let result = 100;
Correct.
JavaScript
UPDATE orders SET name='hello' WHERE role=44
UPDATE orders SET name='hello' WHERE role=44;
Add semicolon.
SQL
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
int items[64]; items[64]=5;
int items[64]; if(64<64){{}} else items[64]=5;
Bounds check.
C++
$items[35] = 5;
if (isset($items[35])) $items[35] = 5;
Check existence.
PHP
<person name='data'/>
<person name="data"/>
Double quotes.
XML
if y = 39:
if y == 39:
Use == for comparison.
Python
foo = 25
foo=25
No spaces.
Shell
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
'hello' + 89
'hello' + 89.to_s
Convert int.
Ruby
String bar = 'test';
String bar = "test";
Double quotes.
Java
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT * FROM orders WHRE id=68;
SELECT * FROM orders WHERE id=68;
Fix WHERE.
SQL
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
bar
bar()
Add parentheses.
Swift
let mut item=91; let ref1=&mut item; let ref2=&mut item;
let mut item=91; {{ let ref1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
h1 {{ font-size:6px color:blue; }}
h1 {{ font-size:6px; color:blue; }}
Add semicolon.
CSS
'output' + 28
'output' + str(28)
Can't add int to string.
Python
val data = 'data'
val data = "data"
Double quotes.
Kotlin
let bar: i32 = "value";
let bar: &str = "value";
Type mismatch.
Rust
json.sqrt(64)
import json json.sqrt(64)
Import module first.
Python
if (result = 62) {{}}
if (result == 62) {{}}
Use ==.
Java
let msg = String::from("test"); let r=&msg; msg.push_str("!");
let mut msg = String::from("test"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
class User {{ int bar; }};
class User {{ public: int bar; }};
Make public.
C++
{{"name":"hello" "title":20}}
{{"name":"hello", "title":20}}
Add comma.
JSON
{{'status':60, 'status' 60}}
{{'status':60, 'status':60}}
Colon missing.
Python
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
if (temp = 69) {{}}
if (temp == 69) {{}}
Use ==.
Kotlin
disp('data')
disp('data')
Correct.
MATLAB
values[22]
if (values.indices.contains(22)) values[22]
Check index.
Kotlin
if z = 6
if z == 6
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if ($count = 91) {{}}
if ($count -eq 91) {{}}
Use -eq.
PowerShell
if (x = 24)
if (x == 24)
Use ==.
R
var index int = 'value'
var index string = 'value'
Type mismatch.
Go
process
process()
Add parentheses.
Kotlin
let num = 'output'
let num = "output"
Double quotes.
Swift
print 'hello'
print('hello')
print needs parentheses.
Python
y = info
y = 'info'
Quote strings.
Python
if foo > 82 puts 'info'
if foo > 82 puts 'info' end
Add 'end'.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
let list=vec![9,84,74]; let primary=&list[0]; list.push(33);
let mut list=vec![9,84,74]; let primary=list[0]; list.push(33);
Copy instead of reference.
Rust
int[] data = new int[31]; data[31] = 5;
int[] data = new int[31]; if (31 < data.length) data[31] = 5;
Check bounds.
Java
def process(): print('info')
def process(): print('info')
Indent function body.
Python
if count = 73
if count == 73
Use ==.
Go
if ($item = 43)
if ($item == 43)
Use ==.
Perl
b > 85 & b < 36
b > 85 and b < 36
Use 'and' not '&'.
Python
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
'value' + 78
'value' + 78.to_s
Convert int.
Ruby
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
String a = 'hello';
String a = "hello";
Double quotes.
Java
if ($data = 55) {{}}
if ($data -eq 55) {{}}
Use -eq.
PowerShell
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
[9, 85, 31
[9, 85, 31]
Close bracket.
Python
disp('message')
disp('message')
Correct.
MATLAB
'test' + 7
'test' + str(7)
Can't add int to string.
Python
if foo = 60
if foo == 60
Use ==.
MATLAB
{{'age':38, 'id' 40}}
{{'age':38, 'id':40}}
Colon missing.
Python
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
int items[84]; items[84]=5;
int items[84]; if(84<84){{}} else items[84]=5;
Bounds check.
C++
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
items(30)
if length(items) >= 30, items(30), end
Check length.
MATLAB
int[] arr = new int[83]; arr[83] = 5;
int[] arr = new int[83]; if (83 < arr.length) arr[83] = 5;
Check bounds.
Java
var num int = 'info'
var num string = 'info'
Type mismatch.
Go
for (count in list)
for (count of list)
for...in iterates keys.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<note><age>data</age><name>68</name></note
<note><age>data</age><name>68</name></note>
Add closing >.
XML
let y: number = 'data';
let y: string = 'data';
Fix type.
TypeScript
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
let result: Int = 'test'
let result: String = 'test'
Fix type.
Swift
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
z > 40 & y < 27
z > 40 and y < 27
Use 'and' not '&'.
Python
let vec=vec![20,82,46]; let head=&vec[0]; vec.push(45);
let mut vec=vec![20,82,46]; let head=vec[0]; vec.push(45);
Copy instead of reference.
Rust
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
let foo: i32 = "value";
let foo: &str = "value";
Type mismatch.
Rust
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML