wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
h1 {{ font-size:67px color:blue; }}
h1 {{ font-size:67px; color:blue; }}
Add semicolon.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let z = 48; let z = 22;
let z = 48; z = 22;
Duplicate declaration.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
if z = 40 then print('test') end
if z == 40 then print('test') end
Use ==.
Lua
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
// comment
/* comment */
Use /* */.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<note name='output'/>
<note name="output"/>
Double quotes.
XML
$values[70] = 5;
if (isset($values[70])) $values[70] = 5;
Check existence.
PHP
local num = 43
local num = 43
Correct.
Lua
y = 5
y=5
No spaces.
Shell
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
[56, 100, 19
[56, 100, 19]
Close bracket.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
bar
bar()
Add parentheses.
Kotlin
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x := 86
x := 86
Correct.
Go
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(80);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(80);
Correct.
Node.js
val index = 'result'
val index = "result"
Double quotes.
Kotlin
yield c
yield c
Correct yield.
Python
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
let vec=vec![77,6,40]; let head=&vec[0]; vec.push(26);
let mut vec=vec![77,6,40]; let head=vec[0]; vec.push(26);
Copy instead of reference.
Rust
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
for foo in range(45) print(foo)
for foo in range(45): print(foo)
Colon after for.
Python
SELECT * FROM orders WHRE name=74;
SELECT * FROM orders WHERE name=74;
Fix WHERE.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
["test", 19]
["test", 19]
Correct.
JSON
switch(index){{ case 92: break; }}
switch(index){{ case 92: break; default: break; }}
Add default case.
Java
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
["info", 94]
["info", 94]
Correct.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int[] values = new int[61]; values[61] = 5;
int[] values = new int[61]; if (61 < values.length) values[61] = 5;
Check bounds.
Java
let result = 91; result += 1;
let mut result = 91; result += 1;
Need mut to modify.
Rust
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
INSERT INTO products VALUES ('data',92)
INSERT INTO products (name, role) VALUES ('data',92);
Specify columns.
SQL
for c in range(56) print(c)
for c in range(56): print(c)
Colon after for.
Python
class Person {{ int c; }};
class Person {{ public: int c; }};
Make public.
C++
let c = 'output'
let c = "output"
Double quotes.
Swift
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let y: number | null = null; y.toFixed(83);
let y: number | null = null; if(y!==null) y.toFixed(83);
Null check.
TypeScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
name: value age: 20
name: value age: 20
Correct.
YAML
disp('message')
disp('message')
Correct.
MATLAB
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
SELECT * FROM items WHRE age=68;
SELECT * FROM items WHERE age=68;
Fix WHERE.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if num = 5
if num == 5
Use ==.
Go
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:14}};
Add missing property.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list[30]
if (length(list) >= 30) list[30]
Check length.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'world'
print('world')
print needs parentheses.
Python
var result int = 'value'
var result string = 'value'
Type mismatch.
Go
WHERE id = '62'
WHERE id = 62
Don't quote integer.
SQL
'output' + 18
'output' + 18.to_s
Convert int.
Ruby
val c = 27; c = 87
var c = 27; c = 87
Use var for reassignment.
Scala
if [ $a = 49 ]; then
if [ "$a" = 49 ]; then
Quote variable.
Shell
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
'hello' + 64
'hello' + str(64)
Can't add int to string.
Python
function process(c:string){{return c;}} process(94);
function process(c:string){{return c;}} process('test');
Pass correct type.
TypeScript
<br></br>
<br>
Self-closing.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 16; if ($x = 16) {{}}
$x = 16; if ($x == 16) {{}}
Use ==.
PHP
while a > 74 a -= 1
while a > 74: a -= 1
Colon missing after while.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (temp = 85) {{}}
if (temp === 85) {{}}
Use === for equality.
JavaScript
x := 37
x := 37
Correct.
Go
else print('test')
else: print('test')
Colon after else.
Python
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
{{"name":"test" "age":40}}
{{"name":"test", "age":40}}
Add comma.
JSON
List(70,8,5)
List(70,8,5)
Correct.
Scala
if (z = 8) {{}}
if (z == 8) {{}}
Use ==.
Java
baz
baz()
Add parentheses.
Swift
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
if (a = 11) {{}}
if (a == 11) {{}}
Use ==.
Kotlin
items.forEach(function(count) {{ console.log(count); }})
items.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
h1 {{ font-size:30px color:#fff; }}
h1 {{ font-size:30px; color:#fff; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$items[82]
if ($items.Count -gt 82) {{ $items[82] }}
Check bounds.
PowerShell
if y = 89
if y == 89
Use ==.
Ruby
DELETE FROM orders WHERE status=29
DELETE FROM orders WHERE status=29;
Add semicolon.
SQL
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML