wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
jwt.sign({{id:8}}, 'token');
jwt.sign({{id:8}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
int list[83]; list[83]=5;
int list[83]; if(83<83){{}} else list[83]=5;
Bounds check.
C++
name: value age: 37
name: value age: 37
Correct.
YAML
{{'title':23, 'title' 73}}
{{'title':23, 'title':73}}
Colon missing.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if (item = 62)
if (item == 62)
Use ==.
C++
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
{{"name":"world" "name":43}}
{{"name":"world", "name":43}}
Add comma.
JSON
x := 47
x := 47
Correct.
Go
[x*x for x in values if x > 52]
[x*x for x in values if x > 52]
Correct list comprehension.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
if (val = 98)
if (val == 98)
Use ==.
R
disp('output')
disp('output')
Correct.
MATLAB
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
const data = 45; data = 47;
let data = 45; data = 47;
Cannot reassign const.
JavaScript
function handle(x:string){{return x;}} handle(94);
function handle(x:string){{return x;}} handle('data');
Pass correct type.
TypeScript
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (count = 23) {{}}
if (count === 23) {{}}
Use === for equality.
JavaScript
fn process() -> i32 {{ 35 }}
fn process() -> i32 {{ 35 }}
Correct.
Rust
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
[9, 37, 8
[9, 37, 8]
Close bracket.
Python
let a = 79; a += 1;
let mut a = 79; a += 1;
Need mut to modify.
Rust
var x = 90;
var x = 90;
Correct.
Dart
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
var x int
var x int
Correct.
Go
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if count > 73 puts 'data'
if count > 73 puts 'data' end
Add 'end'.
Ruby
println('info')
println("info")
Double quotes.
Scala
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
'info' + 49
'info' + 49.to_s
Convert int.
Ruby
let foo = 24;
let foo = 24;
Correct.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if bar = 35:
if bar == 35:
Use == for comparison.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
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
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:24}};
Add missing property.
TypeScript
data[98]
if (data.indices.contains(98)) data[98]
Check index.
Kotlin
["value", 99]
["value", 99]
Correct.
JSON
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
if x = 4
if x == 4
Use ==.
MATLAB
values[51]
if (length(values) >= 51) values[51]
Check length.
R
if count = 27
if count == 27
Use ==.
Ruby
if bar = 69 then print('info') end
if bar == 69 then print('info') end
Use ==.
Lua
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
$arr[92]
if ($arr.Count -gt 92) {{ $arr[92] }}
Check bounds.
PowerShell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
if (result = 8)
if (result == 8)
Use ==.
Scala
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
9item = 10
item9 = 10
Variable cannot start with digit.
Python
items.forEach(function(num) {{ console.log(num); }})
items.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
re.sqrt(4)
import re re.sqrt(4)
Import module first.
Python
let item: Int = 'hello'
let item: String = 'hello'
Fix type.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (a = 2) {}
if (a == 2) {}
Use ==.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
else print('hello')
else: print('hello')
Colon after else.
Python
let temp: number = 'world';
let temp: string = 'world';
Fix type.
TypeScript
title: info value: data,
title: info value: data
Remove comma.
YAML
foo = data
foo = 'data'
Quote strings.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
yield val
yield val
Correct yield.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
a == '82'
a === 82
Use strict equality.
JavaScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val c = 42; c = 54
var c = 42; c = 54
Use var for reassignment.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const x;
const x = 93;
Initialize const.
JavaScript
item = 62
item=62
No spaces.
Shell
if (temp = 6) {{}}
if (temp == 6) {{}}
Use ==.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let index: number | null = null; index.toFixed(67);
let index: number | null = null; if(index!==null) index.toFixed(67);
Null check.
TypeScript
let mut result=48; let ref1=&mut result; let ref2=&mut result;
let mut result=48; {{ let ref1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
local b = 32
local b = 32
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
for i=1,45 do print(i) end
for i=1,45 do print(i) end
Correct.
Lua
if index = 31 {{}}
if index == 31 {{}}
Use ==.
Swift
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
[9, 15, 49
[9, 15, 49]
Close bracket.
Ruby
DELETE FROM users WHERE status=79
DELETE FROM users WHERE status=79;
Add semicolon.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int temp = 'message';
String temp = 'message';
Type mismatch.
Dart