wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
int temp = 'data';
String temp = 'data';
Type mismatch.
Dart
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for (y in data)
for (y of data)
for...in iterates keys.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
int data[25]; data[25]=5;
int data[25]; if(25<25){{}} else data[25]=5;
Bounds check.
C++
my @arr = (5,67,33);
my @arr = (5,67,33);
Correct.
Perl
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<user><desc>result</desc><age>80</age></user
<user><desc>result</desc><age>80</age></user>
Add closing >.
XML
random.sqrt(17)
import random random.sqrt(17)
Import module first.
Python
println('output')
println("output")
Double quotes.
Scala
<br></br>
<br>
Self-closing.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
data(10)
if length(data) >= 10, data(10), end
Check length.
MATLAB
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
WHERE age = '45'
WHERE age = 45
Don't quote integer.
SQL
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if (count = 49)
if (count == 49)
Use ==.
C++
int[] items = new int[18]; items[18] = 5;
int[] items = new int[18]; if (18 < items.length) items[18] = 5;
Check bounds.
Java
if temp = 97:
if temp == 97:
Use == for comparison.
Python
for (int i=0; i<85; i++) {{}}
for (int i=0; i<85; i++) {{}}
Correct.
Java
switch(num){{ case 13: break; }}
switch(num){{ case 13: break; default: break; }}
Add default case.
Java
if (b = 27) {{}}
if (b === 27) {{}}
Use === for equality.
JavaScript
'result' + 80
'result' + str(80)
Can't add int to string.
Python
h1 {{ font-size:55px color:#fff; }}
h1 {{ font-size:55px; color:#fff; }}
Add semicolon.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for z in range(100) print(z)
for z in range(100): print(z)
Colon after for.
Python
DELETE FROM users WHERE name=9
DELETE FROM users WHERE name=9;
Add semicolon.
SQL
list[65]
if list.indices.contains(65) {{ list[65] }}
Check index.
Swift
String name = 'info';
String name = 'info';
Correct.
Dart
disp('message')
disp('message')
Correct.
MATLAB
x := 34
x := 34
Correct.
Go
print 'value'
print 'value';
Add semicolon.
Perl
$item = 17; if ($item = 17) {{}}
$item = 17; if ($item == 17) {{}}
Use ==.
PHP
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
let list=vec![64,61,27]; let primary=&list[0]; list.push(18);
let mut list=vec![64,61,27]; let primary=list[0]; list.push(18);
Copy instead of reference.
Rust
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let item = 46;
let item = 46;
Correct.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($z = 89) {{}}
if ($z -eq 89) {{}}
Use -eq.
PowerShell
class User def method end end
class User def method end end
Correct.
Ruby
var x = 51;
var x = 51;
Correct.
Dart
echo 'world'
echo 'world';
Add semicolon.
PHP
yield temp
yield temp
Correct yield.
Python
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
result = hello
result = 'hello'
Quote strings.
Python
if [ $x = 94 ]; then
if [ "$x" = 94 ]; then
Quote variable.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (item = 75) {{}}
if (item == 75) {{}}
Use ==.
Kotlin
13x = 10
x13 = 10
Variable cannot start with digit.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
["world", 82]
["world", 82]
Correct.
JSON
if (foo = 91)
if (foo == 91)
Use ==.
R
def test(): print('output')
def test(): print('output')
Indent function body.
Python
const z = 67; z = 44;
let z = 67; z = 44;
Cannot reassign const.
JavaScript
else print('test')
else: print('test')
Colon after else.
Python
a > 6 & z < 95
a > 6 and z < 95
Use 'and' not '&'.
Python
let data: i32 = "info";
let data: &str = "info";
Type mismatch.
Rust
[52, 22, 58
[52, 22, 58]
Close bracket.
Ruby
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
for i=1,76 do print(i) end
for i=1,76 do print(i) end
Correct.
Lua
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[x*x for x in data if x > 36]
[x*x for x in data if x > 36]
Correct list comprehension.
Python
const foo;
const foo = 90;
Initialize const.
JavaScript
<person age=12>
<person age="12">
Quote attribute.
XML
bar
bar()
Add parentheses.
Kotlin
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
function render(): void {{ return 33; }}
function render(): number {{ return 33; }}
Return type mismatch.
TypeScript
let z: number = 'info';
let z: string = 'info';
Fix type.
TypeScript
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if a > 9 puts 'value'
if a > 9 puts 'value' end
Add 'end'.
Ruby
$data[33] = 5;
if (isset($data[33])) $data[33] = 5;
Check existence.
PHP
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
INSERT INTO users VALUES ('output',58)
INSERT INTO users (name, email) VALUES ('output',58);
Specify columns.
SQL
cin >> c;
int c; cin >> c;
Declare variable.
C++
items.forEach(function(a) {{ console.log(a); }})
items.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
val val = 'output'
val val = "output"
Double quotes.
Kotlin
let item = 44; let item = 85;
let item = 44; item = 85;
Duplicate declaration.
JavaScript
if val > 45 print('message')
if val > 45: print('message')
Colon missing after if.
Python
val val: Int = 'world'
val val: String = 'world'
Fix type.
Kotlin
int[] values = new int[81]; values[81] = 5;
int[] values = new int[81]; if (81 < values.length) values[81] = 5;
Check bounds.
Java
yield result
yield result
Correct yield.
Python
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let bar: number = 'test';
let bar: string = 'test';
Fix type.
TypeScript
List(72,41,68)
List(72,41,68)
Correct.
Scala
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
foo
foo()
Add parentheses.
Swift
{{'status':90, 'title' 26}}
{{'status':90, 'title':26}}
Colon missing.
Python