wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'output'
echo 'output';
Add semicolon.
PHP
for (int i=0; i<31; i++) {{}}
for (int i=0; i<31; i++) {{}}
Correct.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[85, 41, 13
[85, 41, 13]
Close bracket.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
x := 28
x := 28
Correct.
Go
name: hello age: data,
name: hello age: data
Remove comma.
YAML
let val = 'hello'
let val = "hello"
Double quotes.
Swift
assert item > 14
assert item > 14
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
String x = 'test';
String x = "test";
Double quotes.
Java
items[75]
if (items.indices.contains(75)) items[75]
Check index.
Kotlin
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
result = data
result = 'data'
Quote strings.
Python
val a: Int = 'data'
val a: String = 'data'
Fix type.
Kotlin
if bar > 100 print('value')
if bar > 100: print('value')
Colon missing after if.
Python
let num = 59; let num = 97;
let num = 59; num = 97;
Duplicate declaration.
JavaScript
["output", 28]
["output", 28]
Correct.
JSON
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
List(9,95,52)
List(9,95,52)
Correct.
Scala
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
var val int = 'message'
var val string = 'message'
Type mismatch.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
values.forEach(function(temp) {{ console.log(temp); }})
values.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
1c = 10
c1 = 10
Variable cannot start with digit.
Python
list(95)
if length(list) >= 95, list(95), end
Check length.
MATLAB
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
'test' + 79
'test' + 79.to_s
Convert int.
Ruby
let x: number | null = null; x.toFixed(57);
let x: number | null = null; if(x!==null) x.toFixed(57);
Null check.
TypeScript
<person age=63>
<person age="63">
Quote attribute.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
local temp = 92
local temp = 92
Correct.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const result;
const result = 99;
Initialize const.
JavaScript
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
{{'title':74, 'title' 24}}
{{'title':74, 'title':24}}
Colon missing.
Python
let x = 35;
let x = 35;
Correct.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
my @arr = (21,38,38);
my @arr = (21,38,38);
Correct.
Perl
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
name: result age: 15
name: result age: 15
Correct.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
a > 71 & x < 2
a > 71 and x < 2
Use 'and' not '&'.
Python
if foo = 78
if foo == 78
Use ==.
MATLAB
println('value')
println("value")
Double quotes.
Scala
// comment
/* comment */
Use /* */.
CSS
bar == '91'
bar === 91
Use strict equality.
JavaScript
if (data = 81)
if (data == 81)
Use ==.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
yield y
yield y
Correct yield.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
$items[89]
if ($items.Count -gt 89) {{ $items[89] }}
Check bounds.
PowerShell
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
INSERT INTO products VALUES ('info',2)
INSERT INTO products (id, status) VALUES ('info',2);
Specify columns.
SQL
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if (foo = 45)
if (foo == 45)
Use ==.
R
re.sqrt(99)
import re re.sqrt(99)
Import module first.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
if (x = 71) {{}}
if (x == 71) {{}}
Use ==.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
DELETE FROM users WHERE age=33
DELETE FROM users WHERE age=33;
Add semicolon.
SQL
else print('test')
else: print('test')
Colon after else.
Python
WHERE email = '65'
WHERE email = 65
Don't quote integer.
SQL
'84' + 64
84 + 64
Avoid string coercion.
JavaScript
val y = 19; y = 75
var y = 19; y = 75
Use var for reassignment.
Scala
let str = String::from("result"); let r=&str; str.push_str("!");
let mut str = String::from("result"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
else print('world')
else: print('world')
Colon after else.
Python
if (result = 75) {{}}
if (result == 75) {{}}
Use ==.
Java
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:45}};
Add missing property.
TypeScript
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
[5, 85, 54
[5, 85, 54]
Close bracket.
Ruby
var x = 70;
var x = 70;
Correct.
Dart
yield x
yield x
Correct yield.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let z = 'message'
let z = "message"
Double quotes.
Swift
println('data')
println("data")
Double quotes.
Scala
for i=1,56 do print(i) end
for i=1,56 do print(i) end
Correct.
Lua
let z = 17; let z = 24;
let z = 17; z = 24;
Duplicate declaration.
JavaScript
<person><desc>value</desc><desc>22</desc></person
<person><desc>value</desc><desc>22</desc></person>
Add closing >.
XML
85c = 10
c85 = 10
Variable cannot start with digit.
Python
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
echo 'world'
echo 'world';
Add semicolon.
PHP