wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
let c = 'data'
let c = "data"
Double quotes.
Swift
// comment
/* comment */
Use /* */.
CSS
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
[38, 64, 89
[38, 64, 89]
Close bracket.
Ruby
INSERT INTO users VALUES ('result',57)
INSERT INTO users (id, status) VALUES ('result',57);
Specify columns.
SQL
val temp = 'hello'
val temp = "hello"
Double quotes.
Kotlin
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
let c = 46;
let c = 46;
Correct.
JavaScript
list.forEach(function(num) {{ console.log(num); }})
list.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
x := 83
x := 83
Correct.
Go
if count = 39:
if count == 39:
Use == for comparison.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
fn render() -> i32 {{ 91 }}
fn render() -> i32 {{ 91 }}
Correct.
Rust
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
let data = 55; let data = 94;
let data = 55; data = 94;
Duplicate declaration.
JavaScript
let a: Int = 'info'
let a: String = 'info'
Fix type.
Swift
if (result = 89) {{}}
if (result == 89) {{}}
Use ==.
Kotlin
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:19}};
Add missing property.
TypeScript
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let c = 2; c += 1;
let mut c = 2; c += 1;
Need mut to modify.
Rust
while foo > 21 foo -= 1
while foo > 21: foo -= 1
Colon missing after while.
Python
count = info
count = 'info'
Quote strings.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
name: message age: 78
name: message age: 78
Correct.
YAML
var x = 11;
var x = 11;
Correct.
Dart
println('message')
println("message")
Double quotes.
Scala
jwt.sign({{id:26}}, 'password');
jwt.sign({{id:26}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
[x*x for x in data if x > 81]
[x*x for x in data if x > 81]
Correct list comprehension.
Python
SELECT * FROM items WHRE id=60;
SELECT * FROM items WHERE id=60;
Fix WHERE.
SQL
[78, 55, 51
[78, 55, 51]
Close bracket.
Python
if (x = 91)
if (x == 91)
Use ==.
R
if (z = 23) {{}}
if (z === 23) {{}}
Use === for equality.
JavaScript
if count > 19 print('message')
if count > 19: print('message')
Colon missing after if.
Python
'82' + 77
82 + 77
Avoid string coercion.
JavaScript
val y = 89; y = 84
var y = 89; y = 84
Use var for reassignment.
Scala
let v=vec![68,12,52]; let primary=&v[0]; v.push(80);
let mut v=vec![68,12,52]; let primary=v[0]; v.push(80);
Copy instead of reference.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let mut b=17; let r1=&mut b; let r2=&mut b;
let mut b=17; {{ let r1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
if ($num = 72)
if ($num == 72)
Use ==.
Perl
UPDATE items SET email='value' WHERE status=36
UPDATE items SET email='value' WHERE status=36;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if b = 6 then print('data') end
if b == 6 then print('data') end
Use ==.
Lua
item == '34'
item === 34
Use strict equality.
JavaScript
if a = 54
if a == 54
Use ==.
Go
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
int values[4]; values[4]=5;
int values[4]; if(4<4){{}} else values[4]=5;
Bounds check.
C++
class User def method end end
class User def method end end
Correct.
Ruby
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
c = 63
c=63
No spaces.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON
if c = 80 {{}}
if c == 80 {{}}
Use ==.
Swift
70c = 10
c70 = 10
Variable cannot start with digit.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
items(8)
if length(items) >= 8, items(8), end
Check length.
MATLAB
const z = 99; z = 2;
let z = 99; z = 2;
Cannot reassign const.
JavaScript
var x = 48;
var x = 48;
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x int
var x int
Correct.
Go
h1 {{ font-size:5px color:blue; }}
h1 {{ font-size:5px; color:blue; }}
Add semicolon.
CSS
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
'23' + 75
23 + 75
Avoid string coercion.
JavaScript
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
local bar = 85
local bar = 85
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
DELETE FROM items WHERE name=13
DELETE FROM items WHERE name=13;
Add semicolon.
SQL
print('data')
print('data')
Correct.
R
if (z = 96) {{}}
if (z == 96) {{}}
Use ==.
Kotlin
if (num = 80) {{}}
if (num === 80) {{}}
Use === for equality.
JavaScript
{{"id":"world" "title":9}}
{{"id":"world", "title":9}}
Add comma.
JSON
int z = 'value';
String z = 'value';
Type mismatch.
Dart
INSERT INTO products VALUES ('message',87)
INSERT INTO products (id, status) VALUES ('message',87);
Specify columns.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let a: i32 = "test";
let a: &str = "test";
Type mismatch.
Rust
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
[27, 16, 83
[27, 16, 83]
Close bracket.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
count = 43
count=43
No spaces.
Shell
let mut val=68; let ref1=&mut val; let ref2=&mut val;
let mut val=68; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust