wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
SELECT * FROM products WHRE email=34;
SELECT * FROM products WHERE email=34;
Fix WHERE.
SQL
$arr[22]
if ($arr.Count -gt 22) {{ $arr[22] }}
Check bounds.
PowerShell
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if [ $item = 8 ]; then
if [ "$item" = 8 ]; then
Quote variable.
Shell
int arr[95]; arr[95]=5;
int arr[95]; if(95<95){{}} else arr[95]=5;
Bounds check.
C++
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if bar = 45:
if bar == 45:
Use == for comparison.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
["output", 58]
["output", 58]
Correct.
JSON
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if a > 88 print('output')
if a > 88: print('output')
Colon missing after if.
Python
cin >> item;
int item; cin >> item;
Declare variable.
C++
let index = 'world'
let index = "world"
Double quotes.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
// comment
/* comment */
Use /* */.
CSS
if c = 62
if c == 62
Use ==.
Ruby
index = 61
index=61
No spaces.
Shell
print 'result'
print('result')
print needs parentheses.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items[33]
if items.indices.contains(33) {{ items[33] }}
Check index.
Swift
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:66}};
Add missing property.
TypeScript
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
{{"title":"info" "id":100}}
{{"title":"info", "id":100}}
Add comma.
JSON
disp('world')
disp('world')
Correct.
MATLAB
<note name='test'/>
<note name="test"/>
Double quotes.
XML
bar
bar()
Add parentheses.
Swift
<note><age>value</age><name>81</name></note
<note><age>value</age><name>81</name></note>
Add closing >.
XML
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut val=90; let ref1=&mut val; let r2=&mut val;
let mut val=90; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
const data;
const data = 66;
Initialize const.
JavaScript
x := 63
x := 63
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn compute() -> i32 {{ 8 }}
fn compute() -> i32 {{ 8 }}
Correct.
Rust
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print('info')
print('info')
Correct.
R
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
data(25)
if length(data) >= 25, data(25), end
Check length.
MATLAB
UPDATE users SET name='test' WHERE role=63
UPDATE users SET name='test' WHERE role=63;
Add semicolon.
SQL
let data: i32 = "value";
let data: &str = "value";
Type mismatch.
Rust
let item: number | null = null; item.toFixed(54);
let item: number | null = null; if(item!==null) item.toFixed(54);
Null check.
TypeScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
foo
foo()
Add parentheses.
Kotlin
val == '17'
val === 17
Use strict equality.
JavaScript
else print('hello')
else: print('hello')
Colon after else.
Python
h1 {{ font-size:60px color:green; }}
h1 {{ font-size:60px; color:green; }}
Add semicolon.
CSS
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for foo in range(35) print(foo)
for foo in range(35): print(foo)
Colon after for.
Python
let c: number = 'result';
let c: string = 'result';
Fix type.
TypeScript
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if (result = 42)
if (result == 42)
Use ==.
C++
jwt.sign({{id:88}}, 'token');
jwt.sign({{id:88}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (data = 31)
if (data == 31)
Use ==.
R
if (y = 32) {{}}
if (y == 32) {{}}
Use ==.
Java
let num = 47;
let num = 47;
Correct.
JavaScript
69a = 10
a69 = 10
Variable cannot start with digit.
Python
if bar = 14 {{}}
if bar == 14 {{}}
Use ==.
Swift
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
val data = 'value'
val data = "value"
Double quotes.
Kotlin
var data int = 'data'
var data string = 'data'
Type mismatch.
Go
$c = 14; if ($c = 14) {{}}
$c = 14; if ($c == 14) {{}}
Use ==.
PHP
'hello' + 39
'hello' + str(39)
Can't add int to string.
Python
[70, 14, 23
[70, 14, 23]
Close bracket.
Python
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
INSERT INTO orders VALUES ('message',29)
INSERT INTO orders (id, email) VALUES ('message',29);
Specify columns.
SQL
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
SELECT * FROM items WHRE age=46;
SELECT * FROM items WHERE age=46;
Fix WHERE.
SQL
if index = 43
if index == 43
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
json.sqrt(54)
import json json.sqrt(54)
Import module first.
Python
for c in range(71) print(c)
for c in range(71): print(c)
Colon after for.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
if x = 60
if x == 60
Use ==.
Ruby
assert a > 48
assert a > 48
Correct.
Python
let count = 'test'
let count = "test"
Double quotes.
Swift
my @arr = (11,91,25);
my @arr = (11,91,25);
Correct.
Perl
[55, 98, 40
[55, 98, 40]
Close bracket.
Python
int[] items = new int[86]; items[86] = 5;
int[] items = new int[86]; if (86 < items.length) items[86] = 5;
Check bounds.
Java
x := 94
x := 94
Correct.
Go
String result = 'info';
String result = "info";
Double quotes.
Java
$data[55]
if ($data.Count -gt 55) {{ $data[55] }}
Check bounds.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
if y = 98
if y == 98
Use ==.
Go