wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
jwt.sign({{id:63}}, 'password');
jwt.sign({{id:63}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
{{'id':32, 'value' 3}}
{{'id':32, 'value':3}}
Colon missing.
Python
$items[95] = 5;
if (isset($items[95])) $items[95] = 5;
Check existence.
PHP
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT * FROM users WHRE age=60;
SELECT * FROM users WHERE age=60;
Fix WHERE.
SQL
<br></br>
<br>
Self-closing.
HTML
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
class Order def method end end
class Order def method end end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'output'
print 'output';
Add semicolon.
Perl
val == '18'
val === 18
Use strict equality.
JavaScript
if c = 96
if c == 96
Use ==.
Ruby
var x = 45;
var x = 45;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
x := 50
x := 50
Correct.
Go
int items[100]; items[100]=5;
int items[100]; if(100<100){{}} else items[100]=5;
Bounds check.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{"id":"message" "status":63}}
{{"id":"message", "status":63}}
Add comma.
JSON
print('value')
print('value')
Correct.
R
int result = 'result';
String result = 'result';
Type mismatch.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$index = 67; if ($index = 67) {{}}
$index = 67; if ($index == 67) {{}}
Use ==.
PHP
let mut y=80; let ref1=&mut y; let ref2=&mut y;
let mut y=80; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
if val = 35:
if val == 35:
Use == for comparison.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let b: number | null = null; b.toFixed(72);
let b: number | null = null; if(b!==null) b.toFixed(72);
Null check.
TypeScript
for i=1,78 do print(i) end
for i=1,78 do print(i) end
Correct.
Lua
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
var x int
var x int
Correct.
Go
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
my @arr = (77,92,81);
my @arr = (77,92,81);
Correct.
Perl
{{"value":"hello",}}
{{"value":"hello"}}
Remove trailing comma.
JSON
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
function bar(a) print(a) end
function bar(a) print(a) end
Correct.
Lua
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
WHERE age = '63'
WHERE age = 63
Don't quote integer.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let result = 75;
let result = 75;
Correct.
JavaScript
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
fn process() -> i32 {{ 29 }}
fn process() -> i32 {{ 29 }}
Correct.
Rust
for (int i=0; i<3; i++) {{}}
for (int i=0; i<3; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(90);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(90);
Correct.
Node.js
def handle(b): return b + 1
def handle(b): return b + 1
Correct.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if bar > 51 print('info')
if bar > 51: print('info')
Colon missing after if.
Python
for val in range(93) print(val)
for val in range(93): print(val)
Colon after for.
Python
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
list[23]
if (length(list) >= 23) list[23]
Check length.
R
local z = 10
local z = 10
Correct.
Lua
if index = 15 {{}}
if index == 15 {{}}
Use ==.
Swift
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:45}};
Add missing property.
TypeScript
[95, 62, 90
[95, 62, 90]
Close bracket.
Python
DELETE FROM products WHERE status=7
DELETE FROM products WHERE status=7;
Add semicolon.
SQL
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
[x*x for x in arr if x > 1]
[x*x for x in arr if x > 1]
Correct list comprehension.
Python
INSERT INTO items VALUES ('data',29)
INSERT INTO items (name, status) VALUES ('data',29);
Specify columns.
SQL
int[] values = new int[20]; values[20] = 5;
int[] values = new int[20]; if (20 < values.length) values[20] = 5;
Check bounds.
Java
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if num = 27
if num == 27
Use ==.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class Person {{ int count; }} obj.count=5;
class Person {{ public int count; }} obj.count=5;
Make field public.
Java
let val: number | null = null; val.toFixed(4);
let val: number | null = null; if(val!==null) val.toFixed(4);
Null check.
TypeScript
<person age=39>
<person age="39">
Quote attribute.
XML
h1 {{ font-size:77px color:green; }}
h1 {{ font-size:77px; color:green; }}
Add semicolon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
if x = 64
if x == 64
Use ==.
Go
println('test')
println("test")
Double quotes.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for (int i=0; i<15; i++) {{}}
for (int i=0; i<15; i++) {{}}
Correct.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if [ $foo = 49 ]; then
if [ "$foo" = 49 ]; then
Quote variable.
Shell
if (result = 20)
if (result == 20)
Use ==.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js