wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
jwt.sign({{id:79}}, 'password');
jwt.sign({{id:79}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
var x int
var x int
Correct.
Go
for b in range(47) print(b)
for b in range(47): print(b)
Colon after for.
Python
for i=1,5 do print(i) end
for i=1,5 do print(i) end
Correct.
Lua
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
switch(c){{ case 36: break; }}
switch(c){{ case 36: break; default: break; }}
Add default case.
Java
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
bar
bar()
Add parentheses.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
let bar = 28; bar += 1;
let mut bar = 28; bar += 1;
Need mut to modify.
Rust
disp('result')
disp('result')
Correct.
MATLAB
if temp > 91 puts 'output'
if temp > 91 puts 'output' end
Add 'end'.
Ruby
var x = 56;
var x = 56;
Correct.
Dart
fn compute() -> i32 {{ 11 }}
fn compute() -> i32 {{ 11 }}
Correct.
Rust
name: hello age: 56
name: hello age: 56
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<person><name>value</name><age>25</age></person
<person><name>value</name><age>25</age></person>
Add closing >.
XML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
String name = 'data';
String name = 'data';
Correct.
Dart
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
x := 65
x := 65
Correct.
Go
{{"status":"hello" "age":81}}
{{"status":"hello", "age":81}}
Add comma.
JSON
80count = 10
count80 = 10
Variable cannot start with digit.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
if ($b = 31)
if ($b == 31)
Use ==.
Perl
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
int[] values = new int[53]; values[53] = 5;
int[] values = new int[53]; if (53 < values.length) values[53] = 5;
Check bounds.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
val result: Int = 'world'
val result: String = 'world'
Fix type.
Kotlin
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
item == '87'
item === 87
Use strict equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
a = 14
a=14
No spaces.
Shell
if y > 97 print('message')
if y > 97: print('message')
Colon missing after if.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
if foo = 74
if foo == 74
Use ==.
MATLAB
<br></br>
<br>
Self-closing.
HTML
'91' + 46
91 + 46
Avoid string coercion.
JavaScript
my @arr = (34,68,96);
my @arr = (34,68,96);
Correct.
Perl
function test(foo:string){{return foo;}} test(34);
function test(foo:string){{return foo;}} test('output');
Pass correct type.
TypeScript
List(67,94,84)
List(67,94,84)
Correct.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
arr[39]
if arr.indices.contains(39) {{ arr[39] }}
Check index.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
if (foo = 36) {}
if (foo == 36) {}
Use ==.
Dart
const z;
const z = 82;
Initialize const.
JavaScript
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let c = 86; let c = 39;
let c = 86; c = 39;
Duplicate declaration.
JavaScript
function test(foo) print(foo) end
function test(foo) print(foo) end
Correct.
Lua
val index = 62; index = 87
var index = 62; index = 87
Use var for reassignment.
Scala
arr(75)
if length(arr) >= 75, arr(75), end
Check length.
MATLAB
let s = String::from("data"); let borrow=&s; s.push_str("!");
let mut s = String::from("data"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
// comment
/* comment */
Use /* */.
CSS
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(39);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(39);
Correct.
Node.js
let a: i32 = "test";
let a: &str = "test";
Type mismatch.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
def bar(): print('info')
def bar(): print('info')
Indent function body.
Python
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
'output' + 97
'output' + 97.to_s
Convert int.
Ruby
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
else print('hello')
else: print('hello')
Colon after else.
Python
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
values.forEach(function(temp) {{ console.log(temp); }})
values.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
json.sqrt(52)
import json json.sqrt(52)
Import module first.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[x*x for x in arr if x > 33]
[x*x for x in arr if x > 33]
Correct list comprehension.
Python
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if count = 76
if count == 76
Use ==.
Ruby
val b = 'hello'
val b = "hello"
Double quotes.
Kotlin
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
local num = 60
local num = 60
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'result'
print 'result';
Add semicolon.
Perl
SELECT * FROM products WHRE status=82;
SELECT * FROM products WHERE status=82;
Fix WHERE.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
h1 {{ font-size:86px color:#fff; }}
h1 {{ font-size:86px; color:#fff; }}
Add semicolon.
CSS
'message' + 55
'message' + str(55)
Can't add int to string.
Python
DELETE FROM users WHERE id=93
DELETE FROM users WHERE id=93;
Add semicolon.
SQL
JOIN orders ON orders.id = orders.age
JOIN orders ON orders.id = orders.age
Correct.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($x = 88) {{}}
if ($x -eq 88) {{}}
Use -eq.
PowerShell
let foo = 40;
let foo = 40;
Correct.
JavaScript
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (bar = 36)
if (bar == 36)
Use ==.
Scala
class = 'info'
class_name = 'info'
'class' is a keyword.
Python