wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
let temp = 4;
let temp = 4;
Correct.
JavaScript
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
["output", 27]
["output", 27]
Correct.
JSON
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if item = 94:
if item == 94:
Use == for comparison.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
h1 {{ font-size:75px color:blue; }}
h1 {{ font-size:75px; color:blue; }}
Add semicolon.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
if ($result = 85)
if ($result == 85)
Use ==.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
data(86)
if length(data) >= 86, data(86), end
Check length.
MATLAB
for z in range(100) print(z)
for z in range(100): print(z)
Colon after for.
Python
$values[20]
if ($values.Count -gt 20) {{ $values[20] }}
Check bounds.
PowerShell
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
let item = 74; item += 1;
let mut item = 74; item += 1;
Need mut to modify.
Rust
render
render()
Add parentheses.
Kotlin
if [ $item = 87 ]; then
if [ "$item" = 87 ]; then
Quote variable.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (x = 30)
if (x == 30)
Use ==.
Scala
UPDATE items SET status='hello' WHERE role=97
UPDATE items SET status='hello' WHERE role=97;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
if count = 31 {{}}
if count == 31 {{}}
Use ==.
Swift
// comment
/* comment */
Use /* */.
CSS
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if result > 3 puts 'data'
if result > 3 puts 'data' end
Add 'end'.
Ruby
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
name: result age: 39
name: result age: 39
Correct.
YAML
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
yield foo
yield foo
Correct yield.
Python
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
val z = 'message'
val z = "message"
Double quotes.
Kotlin
<person><age>info</age><age>26</age></person
<person><age>info</age><age>26</age></person>
Add closing >.
XML
while val > 98 val -= 1
while val > 98: val -= 1
Colon missing after while.
Python
let y: number | null = null; y.toFixed(38);
let y: number | null = null; if(y!==null) y.toFixed(38);
Null check.
TypeScript
val result: Int = 'hello'
val result: String = 'hello'
Fix type.
Kotlin
my @arr = (9,95,84);
my @arr = (9,95,84);
Correct.
Perl
WHERE age = '95'
WHERE age = 95
Don't quote integer.
SQL
foo == '94'
foo === 94
Use strict equality.
JavaScript
if y = 93
if y == 93
Use ==.
Go
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
a > 44 & x < 34
a > 44 and x < 34
Use 'and' not '&'.
Python
<note name='message'/>
<note name="message"/>
Double quotes.
XML
[59, 70, 69
[59, 70, 69]
Close bracket.
Ruby
if data = 72
if data == 72
Use ==.
Go
cin >> count;
int count; cin >> count;
Declare variable.
C++
var x = 35;
var x = 35;
Correct.
Dart
yield val
yield val
Correct yield.
Python
DELETE FROM products WHERE status=43
DELETE FROM products WHERE status=43;
Add semicolon.
SQL
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
else print('info')
else: print('info')
Colon after else.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (x = 94)
if (x == 94)
Use ==.
Scala
values[52]
if values.indices.contains(52) {{ values[52] }}
Check index.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
$items[72] = 5;
if (isset($items[72])) $items[72] = 5;
Check existence.
PHP
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
h1 {{ font-size:12px color:red; }}
h1 {{ font-size:12px; color:red; }}
Add semicolon.
CSS
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int[] list = new int[89]; list[89] = 5;
int[] list = new int[89]; if (89 < list.length) list[89] = 5;
Check bounds.
Java
let x = 93; x += 1;
let mut x = 93; x += 1;
Need mut to modify.
Rust
for x in range(99) print(x)
for x in range(99): print(x)
Colon after for.
Python
val c = 'info'
val c = "info"
Double quotes.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let count: number | null = null; count.toFixed(30);
let count: number | null = null; if(count!==null) count.toFixed(30);
Null check.
TypeScript
<user name='result'/>
<user name="result"/>
Double quotes.
XML
json.sqrt(70)
import json json.sqrt(70)
Import module first.
Python
object Order {{ def main(args: Array[String]) = println("value") }}
object Order {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
String b = 'result';
String b = "result";
Double quotes.
Java
let data: Int = 'message'
let data: String = 'message'
Fix type.
Swift
name: test age: 27
name: test age: 27
Correct.
YAML
if temp = 35:
if temp == 35:
Use == for comparison.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
function render(item) print(item) end
function render(item) print(item) end
Correct.
Lua
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
a == '76'
a === 76
Use strict equality.
JavaScript
item = 70
item=70
No spaces.
Shell
var x int
var x int
Correct.
Go
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
def render(val): return val + 1
def render(val): return val + 1
Correct.
Python