wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
[57, 10, 94
[57, 10, 94]
Close bracket.
Python
String index = 'value';
String index = "value";
Double quotes.
Java
disp('result')
disp('result')
Correct.
MATLAB
test
test()
Add parentheses.
Kotlin
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
assert val > 36
assert val > 36
Correct.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
if ($bar = 79) {{}}
if ($bar -eq 79) {{}}
Use -eq.
PowerShell
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (c = 34)
if (c == 34)
Use ==.
R
if [ $y = 49 ]; then
if [ "$y" = 49 ]; then
Quote variable.
Shell
let mut y=16; let ref1=&mut y; let r2=&mut y;
let mut y=16; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
if (val = 6) {{}}
if (val == 6) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
def bar(result): return result + 1
def bar(result): return result + 1
Correct.
Python
if (a = 13)
if (a == 13)
Use ==.
C++
data[51]
if (length(data) >= 51) data[51]
Check length.
R
fn process() -> i32 {{ 22 }}
fn process() -> i32 {{ 22 }}
Correct.
Rust
let v=vec![24,81,100]; let primary=&v[0]; v.push(64);
let mut v=vec![24,81,100]; let primary=v[0]; v.push(64);
Copy instead of reference.
Rust
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
function bar(): void {{ return 30; }}
function bar(): number {{ return 30; }}
Return type mismatch.
TypeScript
// comment
/* comment */
Use /* */.
CSS
if y > 37 print('hello')
if y > 37: print('hello')
Colon missing after if.
Python
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
DELETE FROM orders WHERE age=58
DELETE FROM orders WHERE age=58;
Add semicolon.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
WHERE name = '51'
WHERE name = 51
Don't quote integer.
SQL
a > 60 & a < 7
a > 60 and a < 7
Use 'and' not '&'.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
function baz(y:string){{return y;}} baz(32);
function baz(y:string){{return y;}} baz('value');
Pass correct type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
arr[73]
if (arr.indices.contains(73)) arr[73]
Check index.
Kotlin
h1 {{ font-size:35px color:green; }}
h1 {{ font-size:35px; color:green; }}
Add semicolon.
CSS
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
const foo;
const foo = 69;
Initialize const.
JavaScript
'hello' + 20
'hello' + 20.to_s
Convert int.
Ruby
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
$temp = 86; if ($temp = 86) {{}}
$temp = 86; if ($temp == 86) {{}}
Use ==.
PHP
x := 77
x := 77
Correct.
Go
if ($c = 78)
if ($c == 78)
Use ==.
Perl
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
'33' + 74
33 + 74
Avoid string coercion.
JavaScript
{{'age':4, 'age' 23}}
{{'age':4, 'age':23}}
Colon missing.
Python
item == '100'
item === 100
Use strict equality.
JavaScript
if count = 17
if count == 17
Use ==.
MATLAB
<br></br>
<br>
Self-closing.
HTML
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
let c: i32 = "hello";
let c: &str = "hello";
Type mismatch.
Rust
title: info id: world,
title: info id: world
Remove comma.
YAML
if result = 36
if result == 36
Use ==.
Ruby
for num in range(58) print(num)
for num in range(58): print(num)
Colon after for.
Python
UPDATE orders SET age='output' WHERE role=6
UPDATE orders SET age='output' WHERE role=6;
Add semicolon.
SQL
int arr[69]; arr[69]=5;
int arr[69]; if(69<69){{}} else arr[69]=5;
Bounds check.
C++
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
SELECT * FROM users WHRE name=68;
SELECT * FROM users WHERE name=68;
Fix WHERE.
SQL
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
print 'output'
print 'output';
Add semicolon.
Perl
var a int = 'value'
var a string = 'value'
Type mismatch.
Go
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
'hello' + 57
'hello' + str(57)
Can't add int to string.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
val index = 'world'
val index = "world"
Double quotes.
Kotlin
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
my @arr = (46,61,85);
my @arr = (46,61,85);
Correct.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[12, 52, 60
[12, 52, 60]
Close bracket.
Ruby
function process() {{ return {{key:'data'}} }}
function process() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
data[31]
if data.indices.contains(31) {{ data[31] }}
Check index.
Swift
def compute puts 'value' end
def compute puts 'value' end
Correct.
Ruby
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
bar = result
bar = 'result'
Quote strings.
Python
bar
bar()
Add parentheses.
Swift
if (num = 6) {{}}
if (num == 6) {{}}
Use ==.
Java
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
$items[20]
if ($items.Count -gt 20) {{ $items[20] }}
Check bounds.
PowerShell
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
print('test')
print('test')
Correct.
R
let text = String::from("data"); let borrow=&text; text.push_str("!");
let mut text = String::from("data"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
def test(): print('result')
def test(): print('result')
Indent function body.
Python
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
let bar = 97;
let bar = 97;
Correct.
JavaScript
if z = 95:
if z == 95:
Use == for comparison.
Python
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
36b = 10
b36 = 10
Variable cannot start with digit.
Python
$data[27] = 5;
if (isset($data[27])) $data[27] = 5;
Check existence.
PHP
for c in range(9) print(c)
for c in range(9): print(c)
Colon after for.
Python
<hr></hr>
<hr>
Self-closing.
HTML
let mut count=22; let r1=&mut count; let r2=&mut count;
let mut count=22; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if z = 23
if z == 23
Use ==.
Go
jwt.sign({{id:10}}, 'password');
jwt.sign({{id:10}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js