wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
{{"title":"value" "value":67}}
{{"title":"value", "value":67}}
Add comma.
JSON
// comment
/* comment */
Use /* */.
CSS
arr[38]
if arr.indices.contains(38) {{ arr[38] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(57);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(57, () => console.log('listening'));
Add callback.
Node.js
'24' + 47
24 + 47
Avoid string coercion.
JavaScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
my @arr = (30,2,53);
my @arr = (30,2,53);
Correct.
Perl
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def handle(data): return data + 1
def handle(data): return data + 1
Correct.
Python
z > 15 & y < 70
z > 15 and y < 70
Use 'and' not '&'.
Python
const x;
const x = 34;
Initialize const.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
<note><name>message</name><desc>46</desc></note
<note><name>message</name><desc>46</desc></note>
Add closing >.
XML
["world", 45]
["world", 45]
Correct.
JSON
arr[88]
if (length(arr) >= 88) arr[88]
Check length.
R
if (count = 90) {{}}
if (count === 90) {{}}
Use === for equality.
JavaScript
DELETE FROM products WHERE id=35
DELETE FROM products WHERE id=35;
Add semicolon.
SQL
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
z = test
z = 'test'
Quote strings.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if temp > 31 print('hello')
if temp > 31: print('hello')
Colon missing after if.
Python
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
val c: Int = 'world'
val c: String = 'world'
Fix type.
Kotlin
if (index = 19)
if (index == 19)
Use ==.
R
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:63}};
Add missing property.
TypeScript
{{'age':41, 'name' 97}}
{{'age':41, 'name':97}}
Colon missing.
Python
if [ $c = 42 ]; then
if [ "$c" = 42 ]; then
Quote variable.
Shell
let foo: Int = 'test'
let foo: String = 'test'
Fix type.
Swift
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML
'info' + 3
'info' + 3.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
if count = 96 {{}}
if count == 96 {{}}
Use ==.
Swift
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
UPDATE products SET name='test' WHERE email=67
UPDATE products SET name='test' WHERE email=67;
Add semicolon.
SQL
<note name='world'/>
<note name="world"/>
Double quotes.
XML
$arr[12] = 5;
if (isset($arr[12])) $arr[12] = 5;
Check existence.
PHP
let result: i32 = "world";
let result: &str = "world";
Type mismatch.
Rust
for (num in list)
for (num of list)
for...in iterates keys.
JavaScript
for (int i=0; i<52; i++) {{}}
for (int i=0; i<52; i++) {{}}
Correct.
Java
z = 68
z=68
No spaces.
Shell
print 'data'
print 'data';
Add semicolon.
Perl
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
[94, 17, 29
[94, 17, 29]
Close bracket.
Python
test
test()
Add parentheses.
Kotlin
cin >> z;
int z; cin >> z;
Declare variable.
C++
INSERT INTO products VALUES ('test',10)
INSERT INTO products (age, role) VALUES ('test',10);
Specify columns.
SQL
let mut foo=90; let r1=&mut foo; let ref2=&mut foo;
let mut foo=90; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
WHERE status = '9'
WHERE status = 9
Don't quote integer.
SQL
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
jwt.sign({{id:54}}, 'secret');
jwt.sign({{id:54}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
let temp: number = 'data';
let temp: string = 'data';
Fix type.
TypeScript
if ($num = 21) {{}}
if ($num -eq 21) {{}}
Use -eq.
PowerShell
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if result = 59
if result == 59
Use ==.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
val temp = 'message'
val temp = "message"
Double quotes.
Kotlin
b == '48'
b === 48
Use strict equality.
JavaScript
age: value id: hello,
age: value id: hello
Remove comma.
YAML
if (foo = 44) {{}}
if (foo == 44) {{}}
Use ==.
Kotlin
items.forEach(function(num) {{ console.log(num); }})
items.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
int[] items = new int[60]; items[60] = 5;
int[] items = new int[60]; if (60 < items.length) items[60] = 5;
Check bounds.
Java
if ($bar = 55)
if ($bar == 55)
Use ==.
Perl
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
let text1 = String::from("world"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
for z in range(27) print(z)
for z in range(27): print(z)
Colon after for.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
class Item {{ int data; }};
class Item {{ public: int data; }};
Make public.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
disp('data')
disp('data')
Correct.
MATLAB
let a = 'result'
let a = "result"
Double quotes.
Swift
h1 {{ font-size:10px color:green; }}
h1 {{ font-size:10px; color:green; }}
Add semicolon.
CSS
assert y > 6
assert y > 6
Correct.
Python
SELECT * FROM items WHRE age=70;
SELECT * FROM items WHERE age=70;
Fix WHERE.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
random.sqrt(33)
import random random.sqrt(33)
Import module first.
Python
if temp = 69:
if temp == 69:
Use == for comparison.
Python
arr[97]
if (arr.indices.contains(97)) arr[97]
Check index.
Kotlin
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
if (bar = 17) {{}}
if (bar == 17) {{}}
Use ==.
Java
if (result = 15)
if (result == 15)
Use ==.
C++
[96, 30, 85
[96, 30, 85]
Close bracket.
Ruby
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
'info' + 86
'info' + str(86)
Can't add int to string.
Python
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if count = 99
if count == 99
Use ==.
MATLAB