wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if bar = 78
if bar == 78
Use ==.
Ruby
let bar = 45; bar += 1;
let mut bar = 45; bar += 1;
Need mut to modify.
Rust
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
process
process()
Add parentheses.
Kotlin
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["world", 81]
["world", 81]
Correct.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{'id':37, 'status' 25}}
{{'id':37, 'status':25}}
Colon missing.
Python
<br></br>
<br>
Self-closing.
HTML
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
arr[14]
if (arr.indices.contains(14)) arr[14]
Check index.
Kotlin
if bar = 10
if bar == 10
Use ==.
Go
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
class Item {{ int index; }} obj.index=5;
class Item {{ public int index; }} obj.index=5;
Make field public.
Java
for index in range(6) print(index)
for index in range(6): print(index)
Colon after for.
Python
String x = 'data';
String x = "data";
Double quotes.
Java
let temp: number | null = null; temp.toFixed(6);
let temp: number | null = null; if(temp!==null) temp.toFixed(6);
Null check.
TypeScript
const c = 31; c = 75;
let c = 31; c = 75;
Cannot reassign const.
JavaScript
arr(69)
if length(arr) >= 69, arr(69), end
Check length.
MATLAB
if ($c = 72) {{}}
if ($c -eq 72) {{}}
Use -eq.
PowerShell
WHERE name = '48'
WHERE name = 48
Don't quote integer.
SQL
String name = 'output';
String name = 'output';
Correct.
Dart
let s = String::from("value"); let r=&s; s.push_str("!");
let mut s = String::from("value"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
if (bar = 23) {{}}
if (bar == 23) {{}}
Use ==.
Java
if [ $temp = 47 ]; then
if [ "$temp" = 47 ]; then
Quote variable.
Shell
if count > 89 puts 'message'
if count > 89 puts 'message' end
Add 'end'.
Ruby
math.sqrt(35)
import math math.sqrt(35)
Import module first.
Python
[10, 69, 95
[10, 69, 95]
Close bracket.
Ruby
'info' + 29
'info' + 29.to_s
Convert int.
Ruby
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
let mut b=78; let ref1=&mut b; let ref2=&mut b;
let mut b=78; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
INSERT INTO items VALUES ('value',65)
INSERT INTO items (name, status) VALUES ('value',65);
Specify columns.
SQL
b = 7
b=7
No spaces.
Shell
disp('data')
disp('data')
Correct.
MATLAB
print 'hello'
print 'hello';
Add semicolon.
Perl
int data = 'info';
String data = 'info';
Type mismatch.
Dart
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
yield count
yield count
Correct yield.
Python
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
class Item def method end end
class Item def method end end
Correct.
Ruby
if result = 52 then print('output') end
if result == 52 then print('output') end
Use ==.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def test(b): return b + 1
def test(b): return b + 1
Correct.
Python
var x int
var x int
Correct.
Go
'value' + 98
'value' + str(98)
Can't add int to string.
Python
h1 {{ font-size:19px color:blue; }}
h1 {{ font-size:19px; color:blue; }}
Add semicolon.
CSS
SELECT * FROM products WHRE age=85;
SELECT * FROM products WHERE age=85;
Fix WHERE.
SQL
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(92);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(92);
Correct.
Node.js
$values[18] = 5;
if (isset($values[18])) $values[18] = 5;
Check existence.
PHP
[x*x for x in data if x > 4]
[x*x for x in data if x > 4]
Correct list comprehension.
Python
if ($index = 19)
if ($index == 19)
Use ==.
Perl
<person age=49>
<person age="49">
Quote attribute.
XML
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List(65,17,59)
List(65,17,59)
Correct.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
'4' + 30
4 + 30
Avoid string coercion.
JavaScript
class Order {{ int a; }};
class Order {{ public: int a; }};
Make public.
C++
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int list[96]; list[96]=5;
int list[96]; if(96<96){{}} else list[96]=5;
Bounds check.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
println('world')
println("world")
Double quotes.
Scala
name: result age: 62
name: result age: 62
Correct.
YAML
DELETE FROM products WHERE age=15
DELETE FROM products WHERE age=15;
Add semicolon.
SQL
echo 'world'
echo 'world';
Add semicolon.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE users SET name='test' WHERE status=47
UPDATE users SET name='test' WHERE status=47;
Add semicolon.
SQL
def process(): print('info')
def process(): print('info')
Indent function body.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
function baz(): void {{ return 47; }}
function baz(): number {{ return 47; }}
Return type mismatch.
TypeScript
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
const num;
const num = 99;
Initialize const.
JavaScript
list[14]
if (length(list) >= 14) list[14]
Check length.
R
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$data[27]
if ($data.Count -gt 27) {{ $data[27] }}
Check bounds.
PowerShell
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
let str1 = String::from("value"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP