wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
my @arr = (8,34,71);
my @arr = (8,34,71);
Correct.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[27, 3, 32
[27, 3, 32]
Close bracket.
Python
print 'result'
print 'result';
Add semicolon.
Perl
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
int temp = 'result';
String temp = 'result';
Type mismatch.
Dart
for count in range(32) print(count)
for count in range(32): print(count)
Colon after for.
Python
num = world
num = 'world'
Quote strings.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
render
render()
Add parentheses.
Kotlin
def process(): print('message')
def process(): print('message')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
$items[73] = 5;
if (isset($items[73])) $items[73] = 5;
Check existence.
PHP
if item = 1
if item == 1
Use ==.
Ruby
while data > 45 data -= 1
while data > 45: data -= 1
Colon missing after while.
Python
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
for i=1,61 do print(i) end
for i=1,61 do print(i) end
Correct.
Lua
var x = 98;
var x = 98;
Correct.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Order {{ int b; }};
class Order {{ public: int b; }};
Make public.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
'value' + 100
'value' + str(100)
Can't add int to string.
Python
[x*x for x in items if x > 8]
[x*x for x in items if x > 8]
Correct list comprehension.
Python
h1 {{ font-size:32px color:green; }}
h1 {{ font-size:32px; color:green; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
println('message')
println("message")
Double quotes.
Scala
DELETE FROM items WHERE name=94
DELETE FROM items WHERE name=94;
Add semicolon.
SQL
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
let temp: number | null = null; temp.toFixed(71);
let temp: number | null = null; if(temp!==null) temp.toFixed(71);
Null check.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val y = 'data'
val y = "data"
Double quotes.
Kotlin
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
function render(count:string){{return count;}} render(68);
function render(count:string){{return count;}} render('output');
Pass correct type.
TypeScript
if x = 40
if x == 40
Use ==.
Go
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
items[16]
if (length(items) >= 16) items[16]
Check length.
R
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
num = 55
num=55
No spaces.
Shell
let z = 'test'
let z = "test"
Double quotes.
Swift
jwt.sign({{id:21}}, 'key');
jwt.sign({{id:21}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
fn render() -> i32 {{ 32 }}
fn render() -> i32 {{ 32 }}
Correct.
Rust
switch(c){{ case 7: break; }}
switch(c){{ case 7: break; default: break; }}
Add default case.
Java
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
while y > 17 y -= 1
while y > 17: y -= 1
Colon missing after while.
Python
if ($item = 24)
if ($item == 24)
Use ==.
Perl
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x > 47 & x < 70
x > 47 and x < 70
Use 'and' not '&'.
Python
if (result = 57) {}
if (result == 57) {}
Use ==.
Dart
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:16}};
Add missing property.
TypeScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
let count: number | null = null; count.toFixed(85);
let count: number | null = null; if(count!==null) count.toFixed(85);
Null check.
TypeScript
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
echo 'world'
echo 'world';
Add semicolon.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
my @arr = (74,33,75);
my @arr = (74,33,75);
Correct.
Perl
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
<person age=40>
<person age="40">
Quote attribute.
XML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 48;
var x = 48;
Correct.
Dart
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
name: world age: 23
name: world age: 23
Correct.
YAML
def process(): print('message')
def process(): print('message')
Indent function body.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if (count = 28)
if (count == 28)
Use ==.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if b = 15
if b == 15
Use ==.
Ruby
compute
compute()
Add parentheses.
Swift
data[40]
if data.indices.contains(40) {{ data[40] }}
Check index.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for x in range(19) print(x)
for x in range(19): print(x)
Colon after for.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
$list[33] = 5;
if (isset($list[33])) $list[33] = 5;
Check existence.
PHP
if result > 70 puts 'value'
if result > 70 puts 'value' end
Add 'end'.
Ruby
else print('result')
else: print('result')
Colon after else.
Python
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
let y = 37; y += 1;
let mut y = 37; y += 1;
Need mut to modify.
Rust
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS