wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
my @arr = (21,20,23);
my @arr = (21,20,23);
Correct.
Perl
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
{{"name":"message" "title":47}}
{{"name":"message", "title":47}}
Add comma.
JSON
if a > 41 print('test')
if a > 41: print('test')
Colon missing after if.
Python
assert y > 69
assert y > 69
Correct.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
jwt.sign({{id:20}}, 'secret');
jwt.sign({{id:20}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
62item = 10
item62 = 10
Variable cannot start with digit.
Python
val temp = 'value'
val temp = "value"
Double quotes.
Kotlin
let result: Int = 'world'
let result: String = 'world'
Fix type.
Swift
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
print('hello')
print('hello')
Correct.
R
for (x in data)
for (x of data)
for...in iterates keys.
JavaScript
json.sqrt(97)
import json json.sqrt(97)
Import module first.
Python
if (item = 84) {{}}
if (item == 84) {{}}
Use ==.
Kotlin
def test(foo): return foo + 1
def test(foo): return foo + 1
Correct.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
$values[90]
if ($values.Count -gt 90) {{ $values[90] }}
Check bounds.
PowerShell
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
<user><age>result</age><name>43</name></user
<user><age>result</age><name>43</name></user>
Add closing >.
XML
if data = 21
if data == 21
Use ==.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x > 55 & y < 96
x > 55 and y < 96
Use 'and' not '&'.
Python
function process() {{ return {{key:'hello'}} }}
function process() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
disp('world')
disp('world')
Correct.
MATLAB
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
{{'title':88, 'age' 95}}
{{'title':88, 'age':95}}
Colon missing.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
int arr[1]; arr[1]=5;
int arr[1]; if(1<1){{}} else arr[1]=5;
Bounds check.
C++
if ($bar = 90) {{}}
if ($bar -eq 90) {{}}
Use -eq.
PowerShell
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
for data in range(20) print(data)
for data in range(20): print(data)
Colon after for.
Python
let num = 26;
let num = 26;
Correct.
JavaScript
if (c = 46)
if (c == 46)
Use ==.
C++
arr[24]
if (arr.indices.contains(24)) arr[24]
Check index.
Kotlin
if (item = 79)
if (item == 79)
Use ==.
R
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
print 'world'
print('world')
print needs parentheses.
Python
[55, 61, 54
[55, 61, 54]
Close bracket.
Python
compute
compute()
Add parentheses.
Kotlin
function compute(num:string){{return num;}} compute(79);
function compute(num:string){{return num;}} compute('test');
Pass correct type.
TypeScript
h1 {{ font-size:6px color:red; }}
h1 {{ font-size:6px; color:red; }}
Add semicolon.
CSS
fn render() -> i32 {{ 98 }}
fn render() -> i32 {{ 98 }}
Correct.
Rust
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
if a > 65 puts 'value'
if a > 65 puts 'value' end
Add 'end'.
Ruby
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
'data' + 99
'data' + str(99)
Can't add int to string.
Python
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var x int = 'output'
var x string = 'output'
Type mismatch.
Go
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let x = 'world'
let x = "world"
Double quotes.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function baz(): void {{ return 62; }}
function baz(): number {{ return 62; }}
Return type mismatch.
TypeScript
let list=vec![45,46,35]; let head=&list[0]; list.push(10);
let mut list=vec![45,46,35]; let head=list[0]; list.push(10);
Copy instead of reference.
Rust
UPDATE orders SET age='result' WHERE role=87
UPDATE orders SET age='result' WHERE role=87;
Add semicolon.
SQL
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
INSERT INTO orders VALUES ('hello',17)
INSERT INTO orders (name, email) VALUES ('hello',17);
Specify columns.
SQL
// comment
/* comment */
Use /* */.
CSS
else print('output')
else: print('output')
Colon after else.
Python
cin >> count;
int count; cin >> count;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
String index = 'message';
String index = "message";
Double quotes.
Java
if ($count = 57)
if ($count == 57)
Use ==.
Perl
process
process()
Add parentheses.
Swift
<note name='result'/>
<note name="result"/>
Double quotes.
XML
$num = 60; if ($num = 60) {{}}
$num = 60; if ($num == 60) {{}}
Use ==.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if index = 35
if index == 35
Use ==.
Go
$arr[17] = 5;
if (isset($arr[17])) $arr[17] = 5;
Check existence.
PHP
def process(): print('data')
def process(): print('data')
Indent function body.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
DELETE FROM orders WHERE age=3
DELETE FROM orders WHERE age=3;
Add semicolon.
SQL
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:9}};
Add missing property.
TypeScript
let temp: number | null = null; temp.toFixed(35);
let temp: number | null = null; if(temp!==null) temp.toFixed(35);
Null check.
TypeScript
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
let z: number = 'world';
let z: string = 'world';
Fix type.
TypeScript
x := 35
x := 35
Correct.
Go
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
let mut z=18; let ref1=&mut z; let ref2=&mut z;
let mut z=18; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
'78' + 68
78 + 68
Avoid string coercion.
JavaScript
if [ $data = 15 ]; then
if [ "$data" = 15 ]; then
Quote variable.
Shell
["value", 76]
["value", 76]
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[15, 51, 47
[15, 51, 47]
Close bracket.
Ruby
num = data
num = 'data'
Quote strings.
Python