wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if b = 35 {{}}
if b == 35 {{}}
Use ==.
Swift
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
y == '95'
y === 95
Use strict equality.
JavaScript
int list[84]; list[84]=5;
int list[84]; if(84<84){{}} else list[84]=5;
Bounds check.
C++
let foo: Int = 'info'
let foo: String = 'info'
Fix type.
Swift
<br></br>
<br>
Self-closing.
HTML
if [ $bar = 87 ]; then
if [ "$bar" = 87 ]; then
Quote variable.
Shell
if index = 10:
if index == 10:
Use == for comparison.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
'31' + 23
31 + 23
Avoid string coercion.
JavaScript
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if index = 15
if index == 15
Use ==.
Ruby
$temp = 65; if ($temp = 65) {{}}
$temp = 65; if ($temp == 65) {{}}
Use ==.
PHP
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x int
var x int
Correct.
Go
if index > 26 print('result')
if index > 26: print('result')
Colon missing after if.
Python
var x = 78;
var x = 78;
Correct.
Dart
if item = 1
if item == 1
Use ==.
MATLAB
<person age=60>
<person age="60">
Quote attribute.
XML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
items(85)
if length(items) >= 85, items(85), end
Check length.
MATLAB
class User def method end end
class User def method end end
Correct.
Ruby
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
print 'hello'
print('hello')
print needs parentheses.
Python
cin >> val;
int val; cin >> val;
Declare variable.
C++
local z = 3
local z = 3
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
DELETE FROM items WHERE id=12
DELETE FROM items WHERE id=12;
Add semicolon.
SQL
String name = 'test';
String name = 'test';
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let mut b=84; let ref1=&mut b; let ref2=&mut b;
let mut b=84; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
const result;
const result = 34;
Initialize const.
JavaScript
if (z = 11)
if (z == 11)
Use ==.
C++
if (z = 98)
if (z == 98)
Use ==.
R
List(84,47,99)
List(84,47,99)
Correct.
Scala
{{'status':54, 'name' 64}}
{{'status':54, 'name':64}}
Colon missing.
Python
// comment
/* comment */
Use /* */.
CSS
let bar = 73; let bar = 38;
let bar = 73; bar = 38;
Duplicate declaration.
JavaScript
data[95]
if (data.indices.contains(95)) data[95]
Check index.
Kotlin
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
'output' + 95
'output' + str(95)
Can't add int to string.
Python
for num in range(42) print(num)
for num in range(42): print(num)
Colon after for.
Python
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
val num = 'output'
val num = "output"
Double quotes.
Kotlin
switch(a){{ case 30: break; }}
switch(a){{ case 30: break; default: break; }}
Add default case.
Java
String data = 'info';
String data = "info";
Double quotes.
Java
$list[81]
if ($list.Count -gt 81) {{ $list[81] }}
Check bounds.
PowerShell
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:26}};
Add missing property.
TypeScript
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
if (num = 59) {}
if (num == 59) {}
Use ==.
Dart
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
function render(a:string){{return a;}} render(93);
function render(a:string){{return a;}} render('info');
Pass correct type.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
JOIN orders ON products.id = orders.id
JOIN orders ON products.id = orders.id
Correct.
SQL
if a = 46
if a == 46
Use ==.
Go
a > 28 & a < 2
a > 28 and a < 2
Use 'and' not '&'.
Python
<person><name>output</name><age>88</age></person
<person><name>output</name><age>88</age></person>
Add closing >.
XML
for i=1,17 do print(i) end
for i=1,17 do print(i) end
Correct.
Lua
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
WHERE email = '58'
WHERE email = 58
Don't quote integer.
SQL
if (num = 69) {{}}
if (num == 69) {{}}
Use ==.
Kotlin
9y = 10
y9 = 10
Variable cannot start with digit.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<hr></hr>
<hr>
Self-closing.
HTML
'message' + 1
'message' + 1.to_s
Convert int.
Ruby
UPDATE products SET status='value' WHERE role=70
UPDATE products SET status='value' WHERE role=70;
Add semicolon.
SQL
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
print('world')
print('world')
Correct.
R
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
name: value age: 85
name: value age: 85
Correct.
YAML
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
fn bar() -> i32 {{ 9 }}
fn bar() -> i32 {{ 9 }}
Correct.
Rust
{{"title":"message" "age":91}}
{{"title":"message", "age":91}}
Add comma.
JSON
if (z = 59)
if (z == 59)
Use ==.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
title: info status: data,
title: info status: data
Remove comma.
YAML
if x = 46 then print('world') end
if x == 46 then print('world') end
Use ==.
Lua
[19, 26, 24
[19, 26, 24]
Close bracket.
Python
bar
bar()
Add parentheses.
Swift
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
yield num
yield num
Correct yield.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$data[23] = 5;
if (isset($data[23])) $data[23] = 5;
Check existence.
PHP
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++