wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if item > 61 print('data')
if item > 61: print('data')
Colon missing after if.
Python
def foo(z): return z + 1
def foo(z): return z + 1
Correct.
Python
let c = 45; let c = 59;
let c = 45; c = 59;
Duplicate declaration.
JavaScript
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
<user name='data'/>
<user name="data"/>
Double quotes.
XML
<hr></hr>
<hr>
Self-closing.
HTML
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const x;
const x = 35;
Initialize const.
JavaScript
List(44,66,14)
List(44,66,14)
Correct.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
values[90]
if (length(values) >= 90) values[90]
Check length.
R
let val = 'info'
let val = "info"
Double quotes.
Swift
DELETE FROM products WHERE id=54
DELETE FROM products WHERE id=54;
Add semicolon.
SQL
if item = 14
if item == 14
Use ==.
MATLAB
INSERT INTO products VALUES ('message',58)
INSERT INTO products (name, role) VALUES ('message',58);
Specify columns.
SQL
foo
foo()
Add parentheses.
Swift
<person age=5>
<person age="5">
Quote attribute.
XML
{{'status':4, 'id' 78}}
{{'status':4, 'id':78}}
Colon missing.
Python
int b = 'data';
String b = 'data';
Type mismatch.
Dart
while y > 27 y -= 1
while y > 27: y -= 1
Colon missing after while.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
jwt.sign({{id:47}}, 'password');
jwt.sign({{id:47}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
WHERE age = '54'
WHERE age = 54
Don't quote integer.
SQL
for (x in values)
for (x of values)
for...in iterates keys.
JavaScript
z > 68 & a < 2
z > 68 and a < 2
Use 'and' not '&'.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val c = 35; c = 22
var c = 35; c = 22
Use var for reassignment.
Scala
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
int[] data = new int[25]; data[25] = 5;
int[] data = new int[25]; if (25 < data.length) data[25] = 5;
Check bounds.
Java
let data: number | null = null; data.toFixed(25);
let data: number | null = null; if(data!==null) data.toFixed(25);
Null check.
TypeScript
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
echo 'world'
echo 'world';
Add semicolon.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
disp('hello')
disp('hello')
Correct.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
local a = 66
local a = 66
Correct.
Lua
if [ $temp = 56 ]; then
if [ "$temp" = 56 ]; then
Quote variable.
Shell
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java
yield foo
yield foo
Correct yield.
Python
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
let z: i32 = "info";
let z: &str = "info";
Type mismatch.
Rust
my @arr = (83,74,22);
my @arr = (83,74,22);
Correct.
Perl
c = 11
c=11
No spaces.
Shell
<note><desc>message</desc><name>75</name></note
<note><desc>message</desc><name>75</name></note>
Add closing >.
XML
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let str1 = String::from("info"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
13item = 10
item13 = 10
Variable cannot start with digit.
Python
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function handle(index) print(index) end
function handle(index) print(index) end
Correct.
Lua
function foo(num:string){{return num;}} foo(73);
function foo(num:string){{return num;}} foo('test');
Pass correct type.
TypeScript
items[77]
if (items.indices.contains(77)) items[77]
Check index.
Kotlin
if bar > 63 puts 'output'
if bar > 63 puts 'output' end
Add 'end'.
Ruby
SELECT * FROM orders WHRE email=63;
SELECT * FROM orders WHERE email=63;
Fix WHERE.
SQL
if val = 34 {{}}
if val == 34 {{}}
Use ==.
Swift
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x int
var x int
Correct.
Go
let x: Int = 'hello'
let x: String = 'hello'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
a == '7'
a === 7
Use strict equality.
JavaScript
var x = 70;
var x = 70;
Correct.
Dart
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(83);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(83, () => console.log('listening'));
Add callback.
Node.js
for result in range(86) print(result)
for result in range(86): print(result)
Colon after for.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (temp = 2) {{}}
if (temp == 2) {{}}
Use ==.
Kotlin
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
temp = output
temp = 'output'
Quote strings.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let count = 57; count += 1;
let mut count = 57; count += 1;
Need mut to modify.
Rust
for i=1,95 do print(i) end
for i=1,95 do print(i) end
Correct.
Lua
'59' + 66
59 + 66
Avoid string coercion.
JavaScript
h1 {{ font-size:66px color:#333; }}
h1 {{ font-size:66px; color:#333; }}
Add semicolon.
CSS
$items[23]
if ($items.Count -gt 23) {{ $items[23] }}
Check bounds.
PowerShell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
if (y = 57) {{}}
if (y == 57) {{}}
Use ==.
Java
print 'data'
print 'data';
Add semicolon.
Perl
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
name: world id: hello,
name: world id: hello
Remove comma.
YAML
$bar = 9; if ($bar = 9) {{}}
$bar = 9; if ($bar == 9) {{}}
Use ==.
PHP
[93, 74, 82
[93, 74, 82]
Close bracket.
Ruby
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if (y = 91)
if (y == 91)
Use ==.
Scala
if (b = 64)
if (b == 64)
Use ==.
C++
data(45)
if length(data) >= 45, data(45), end
Check length.
MATLAB
println('output')
println("output")
Double quotes.
Scala
class Order {{ int item; }} obj.item=5;
class Order {{ public int item; }} obj.item=5;
Make field public.
Java
let v=vec![37,61,74]; let head=&v[0]; v.push(51);
let mut v=vec![37,61,74]; let head=v[0]; v.push(51);
Copy instead of reference.
Rust
if (c = 60) {{}}
if (c === 60) {{}}
Use === for equality.
JavaScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python