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
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
["info", 71]
["info", 71]
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(29);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(29);
Correct.
Node.js
function handle(data:string){{return data;}} handle(45);
function handle(data:string){{return data;}} handle('info');
Pass correct type.
TypeScript
88x = 10
x88 = 10
Variable cannot start with digit.
Python
let mut bar=52; let r1=&mut bar; let ref2=&mut bar;
let mut bar=52; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
$data[34] = 5;
if (isset($data[34])) $data[34] = 5;
Check existence.
PHP
var x = 76;
var x = 76;
Correct.
Dart
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
if val = 79:
if val == 79:
Use == for comparison.
Python
// comment
/* comment */
Use /* */.
CSS
for c in range(85) print(c)
for c in range(85): print(c)
Colon after for.
Python
jwt.sign({{id:9}}, 'password');
jwt.sign({{id:9}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (item = 21) {{}}
if (item === 21) {{}}
Use === for equality.
JavaScript
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
arr[32]
if (arr.indices.contains(32)) arr[32]
Check index.
Kotlin
<br></br>
<br>
Self-closing.
HTML
String name = 'output';
String name = 'output';
Correct.
Dart
int a = 'test';
String a = 'test';
Type mismatch.
Dart
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
item = 79
item=79
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
value: data name: test,
value: data name: test
Remove comma.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
result == '26'
result === 26
Use strict equality.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if val = 94
if val == 94
Use ==.
MATLAB
<user><age>hello</age><age>67</age></user
<user><age>hello</age><age>67</age></user>
Add closing >.
XML
let foo: Int = 'info'
let foo: String = 'info'
Fix type.
Swift
'result' + 40
'result' + str(40)
Can't add int to string.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
disp('message')
disp('message')
Correct.
MATLAB
if ($temp = 42) {{}}
if ($temp -eq 42) {{}}
Use -eq.
PowerShell
class Person {{ int data; }} obj.data=5;
class Person {{ public int data; }} obj.data=5;
Make field public.
Java
{{'age':29, 'title' 1}}
{{'age':29, 'title':1}}
Colon missing.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
b > 90 & y < 37
b > 90 and y < 37
Use 'and' not '&'.
Python
assert foo > 18
assert foo > 18
Correct.
Python
fn render() -> i32 {{ 20 }}
fn render() -> i32 {{ 20 }}
Correct.
Rust
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
data(53)
if length(data) >= 53, data(53), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
const data;
const data = 89;
Initialize const.
JavaScript
for i=1,38 do print(i) end
for i=1,38 do print(i) end
Correct.
Lua
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
my @arr = (80,80,3);
my @arr = (80,80,3);
Correct.
Perl
yield data
yield data
Correct yield.
Python
let num: number = 'test';
let num: string = 'test';
Fix type.
TypeScript
INSERT INTO users VALUES ('value',4)
INSERT INTO users (id, email) VALUES ('value',4);
Specify columns.
SQL
'data' + 65
'data' + 65.to_s
Convert int.
Ruby
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
UPDATE items SET id='result' WHERE status=45
UPDATE items SET id='result' WHERE status=45;
Add semicolon.
SQL
if item = 75 then print('test') end
if item == 75 then print('test') end
Use ==.
Lua
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
if y > 11 puts 'value'
if y > 11 puts 'value' end
Add 'end'.
Ruby
else print('value')
else: print('value')
Colon after else.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[57, 2, 80
[57, 2, 80]
Close bracket.
Ruby
switch(count){{ case 100: break; }}
switch(count){{ case 100: break; default: break; }}
Add default case.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
x := 10
x := 10
Correct.
Go
if c = 96
if c == 96
Use ==.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if index = 13
if index == 13
Use ==.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const data = 87; data = 22;
let data = 87; data = 22;
Cannot reassign const.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
h1 {{ font-size:14px color:blue; }}
h1 {{ font-size:14px; color:blue; }}
Add semicolon.
CSS
item = data
item = 'data'
Quote strings.
Python
if (index = 49) {{}}
if (index == 49) {{}}
Use ==.
Kotlin
$items[5]
if ($items.Count -gt 5) {{ $items[5] }}
Check bounds.
PowerShell
SELECT * FROM products WHRE status=99;
SELECT * FROM products WHERE status=99;
Fix WHERE.
SQL
if [ $val = 62 ]; then
if [ "$val" = 62 ]; then
Quote variable.
Shell
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if (num = 98)
if (num == 98)
Use ==.
R
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
'67' + 8
67 + 8
Avoid string coercion.
JavaScript
val foo = 'message'
val foo = "message"
Double quotes.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
foo
foo()
Add parentheses.
Kotlin
DELETE FROM products WHERE email=91
DELETE FROM products WHERE email=91;
Add semicolon.
SQL
if ($c = 42)
if ($c == 42)
Use ==.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(65);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(65, () => console.log('listening'));
Add callback.
Node.js
let s1 = String::from("test"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<person age=33>
<person age="33">
Quote attribute.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (item = 61) {}
if (item == 61) {}
Use ==.
Dart