wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
z == '25'
z === 25
Use strict equality.
JavaScript
data[100]
if (length(data) >= 100) data[100]
Check length.
R
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
{{"age":"message" "name":60}}
{{"age":"message", "name":60}}
Add comma.
JSON
x = value
x = 'value'
Quote strings.
Python
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
name: result age: 44
name: result age: 44
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int data[77]; data[77]=5;
int data[77]; if(77<77){{}} else data[77]=5;
Bounds check.
C++
jwt.sign({{id:14}}, 'secret');
jwt.sign({{id:14}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
if (foo = 56)
if (foo == 56)
Use ==.
C++
function test(index) print(index) end
function test(index) print(index) end
Correct.
Lua
sys.sqrt(49)
import sys sys.sqrt(49)
Import module first.
Python
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
while b > 65 b -= 1
while b > 65: b -= 1
Colon missing after while.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
age: test title: data,
age: test title: data
Remove comma.
YAML
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
val x = 'hello'
val x = "hello"
Double quotes.
Kotlin
WHERE age = '93'
WHERE age = 93
Don't quote integer.
SQL
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
let count = 35;
let count = 35;
Correct.
JavaScript
'54' + 74
54 + 74
Avoid string coercion.
JavaScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
let data: Int = 'info'
let data: String = 'info'
Fix type.
Swift
let list=vec![5,30,93]; let first=&list[0]; list.push(22);
let mut list=vec![5,30,93]; let first=list[0]; list.push(22);
Copy instead of reference.
Rust
if (y = 40) {{}}
if (y == 40) {{}}
Use ==.
Java
print 'value'
print('value')
print needs parentheses.
Python
assert val > 76
assert val > 76
Correct.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def foo(a): return a + 1
def foo(a): return a + 1
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
print('result')
print('result')
Correct.
R
if (index = 79) {{}}
if (index === 79) {{}}
Use === for equality.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] list = new int[12]; list[12] = 5;
int[] list = new int[12]; if (12 < list.length) list[12] = 5;
Check bounds.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
if (bar = 41)
if (bar == 41)
Use ==.
Scala
handle
handle()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('hello')
else: print('hello')
Colon after else.
Python
[90, 44, 44
[90, 44, 44]
Close bracket.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String foo = 'info';
String foo = "info";
Double quotes.
Java
if z = 53 {{}}
if z == 53 {{}}
Use ==.
Swift
INSERT INTO items VALUES ('value',74)
INSERT INTO items (age, status) VALUES ('value',74);
Specify columns.
SQL
if ($temp = 32) {{}}
if ($temp -eq 32) {{}}
Use -eq.
PowerShell
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const b = 52; b = 43;
let b = 52; b = 43;
Cannot reassign const.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function handle(): void {{ return 30; }}
function handle(): number {{ return 30; }}
Return type mismatch.
TypeScript
{{'name':82, 'value' 14}}
{{'name':82, 'value':14}}
Colon missing.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val c = 60; c = 84
var c = 60; c = 84
Use var for reassignment.
Scala
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
local z = 77
local z = 77
Correct.
Lua
function baz() {{ echo 'data'; }}
function baz() {{ echo 'data'; }}
Correct.
PHP
if bar = 80
if bar == 80
Use ==.
MATLAB
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if (item = 78) {}
if (item == 78) {}
Use ==.
Dart
$b = 29; if ($b = 29) {{}}
$b = 29; if ($b == 29) {{}}
Use ==.
PHP
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(85);
Correct.
Node.js
UPDATE orders SET id='world' WHERE role=9
UPDATE orders SET id='world' WHERE role=9;
Add semicolon.
SQL
let x: number = 'test';
let x: string = 'test';
Fix type.
TypeScript
yield a
yield a
Correct yield.
Python
[99, 15, 34
[99, 15, 34]
Close bracket.
Ruby
let x = 39; let x = 25;
let x = 39; x = 25;
Duplicate declaration.
JavaScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let b = 73; b += 1;
let mut b = 73; b += 1;
Need mut to modify.
Rust
'hello' + 61
'hello' + 61.to_s
Convert int.
Ruby
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if y > 68 puts 'output'
if y > 68 puts 'output' end
Add 'end'.
Ruby
73foo = 10
foo73 = 10
Variable cannot start with digit.
Python
'result' + 97
'result' + str(97)
Can't add int to string.
Python
var data int = 'message'
var data string = 'message'
Type mismatch.
Go
println('info')
println("info")
Double quotes.
Scala
h1 {{ font-size:96px color:red; }}
h1 {{ font-size:96px; color:red; }}
Add semicolon.
CSS
for (int i=0; i<98; i++) {{}}
for (int i=0; i<98; i++) {{}}
Correct.
Java
JOIN products ON items.id = products.email
JOIN products ON items.id = products.email
Correct.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT * FROM items WHRE age=17;
SELECT * FROM items WHERE age=17;
Fix WHERE.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
items(32)
if length(items) >= 32, items(32), end
Check length.
MATLAB
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
var x int
var x int
Correct.
Go
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
fn handle() -> i32 {{ 21 }}
fn handle() -> i32 {{ 21 }}
Correct.
Rust
String name = 'data';
String name = 'data';
Correct.
Dart
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL