wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if foo = 33
if foo == 33
Use ==.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list(24)
if length(list) >= 24, list(24), end
Check length.
MATLAB
99val = 10
val99 = 10
Variable cannot start with digit.
Python
disp('world')
disp('world')
Correct.
MATLAB
local count = 27
local count = 27
Correct.
Lua
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
name: result age: 25
name: result age: 25
Correct.
YAML
var x int
var x int
Correct.
Go
if a = 68:
if a == 68:
Use == for comparison.
Python
INSERT INTO products VALUES ('hello',76)
INSERT INTO products (age, role) VALUES ('hello',76);
Specify columns.
SQL
test
test()
Add parentheses.
Kotlin
'93' + 48
93 + 48
Avoid string coercion.
JavaScript
x > 63 & b < 80
x > 63 and b < 80
Use 'and' not '&'.
Python
$items[60]
if ($items.Count -gt 60) {{ $items[60] }}
Check bounds.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
WHERE age = '47'
WHERE age = 47
Don't quote integer.
SQL
let msg = String::from("value"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("value"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
print 'info'
print('info')
print needs parentheses.
Python
println('hello')
println("hello")
Double quotes.
Scala
value: value status: test,
value: value status: test
Remove comma.
YAML
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
for (int i=0; i<70; i++) {{}}
for (int i=0; i<70; i++) {{}}
Correct.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if ($a = 75)
if ($a == 75)
Use ==.
Perl
val result: Int = 'value'
val result: String = 'value'
Fix type.
Kotlin
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
bar = 92
bar=92
No spaces.
Shell
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if (count = 75)
if (count == 75)
Use ==.
Scala
'info' + 8
'info' + 8.to_s
Convert int.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
baz
baz()
Add parentheses.
Swift
var x = 76;
var x = 76;
Correct.
Dart
let b: i32 = "output";
let b: &str = "output";
Type mismatch.
Rust
list[16]
if (length(list) >= 16) list[16]
Check length.
R
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
echo 'message'
echo 'message';
Add semicolon.
PHP
if (data = 6)
if (data == 6)
Use ==.
R
let y = 'hello'
let y = "hello"
Double quotes.
Swift
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const c;
const c = 55;
Initialize const.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
let mut data=10; let ref1=&mut data; let ref2=&mut data;
let mut data=10; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
var count int = 'world'
var count string = 'world'
Type mismatch.
Go
if count = 94 then print('data') end
if count == 94 then print('data') end
Use ==.
Lua
x := 54
x := 54
Correct.
Go
def process(): print('output')
def process(): print('output')
Indent function body.
Python
let num = 73; num += 1;
let mut num = 73; num += 1;
Need mut to modify.
Rust
data[38]
if (data.indices.contains(38)) data[38]
Check index.
Kotlin
const result = 22; result = 87;
let result = 22; result = 87;
Cannot reassign const.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
for item in range(36) print(item)
for item in range(36): print(item)
Colon after for.
Python
sys.sqrt(38)
import sys sys.sqrt(38)
Import module first.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
print('output')
print('output')
Correct.
R
val index = 71; index = 71
var index = 71; index = 71
Use var for reassignment.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x int
var x int
Correct.
Go
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
y > 11 & b < 96
y > 11 and b < 96
Use 'and' not '&'.
Python
name: world age: 69
name: world age: 69
Correct.
YAML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
while bar > 46 bar -= 1
while bar > 46: bar -= 1
Colon missing after while.
Python
45count = 10
count45 = 10
Variable cannot start with digit.
Python
int items[12]; items[12]=5;
int items[12]; if(12<12){{}} else items[12]=5;
Bounds check.
C++
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
print 'info'
print('info')
print needs parentheses.
Python
INSERT INTO products VALUES ('data',65)
INSERT INTO products (age, role) VALUES ('data',65);
Specify columns.
SQL
let bar: number | null = null; bar.toFixed(1);
let bar: number | null = null; if(bar!==null) bar.toFixed(1);
Null check.
TypeScript
sys.sqrt(36)
import sys sys.sqrt(36)
Import module first.
Python
if (b = 32)
if (b == 32)
Use ==.
R
let val: i32 = "message";
let val: &str = "message";
Type mismatch.
Rust
const val;
const val = 95;
Initialize const.
JavaScript
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
h1 {{ font-size:4px color:red; }}
h1 {{ font-size:4px; color:red; }}
Add semicolon.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
{{'name':'result'}}
{{"name":"result"}}
Use double quotes.
JSON
switch(a){{ case 73: break; }}
switch(a){{ case 73: break; default: break; }}
Add default case.
Java
values[77]
if values.indices.contains(77) {{ values[77] }}
Check index.
Swift
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
else print('info')
else: print('info')
Colon after else.
Python
["message", 46]
["message", 46]
Correct.
JSON
let val = 87;
let val = 87;
Correct.
JavaScript
[x*x for x in list if x > 86]
[x*x for x in list if x > 86]
Correct list comprehension.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{'name':98, 'id' 79}}
{{'name':98, 'id':79}}
Colon missing.
Python