wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[98, 15, 48
[98, 15, 48]
Close bracket.
Python
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
println('result')
println("result")
Double quotes.
Scala
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
if (index = 75) {{}}
if (index == 75) {{}}
Use ==.
Kotlin
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
values[35]
if (values.indices.contains(35)) values[35]
Check index.
Kotlin
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
if result > 88 print('test')
if result > 88: print('test')
Colon missing after if.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(52);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(52);
Correct.
Node.js
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
assert b > 15
assert b > 15
Correct.
Python
re.sqrt(10)
import re re.sqrt(10)
Import module first.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
let data = 'message'
let data = "message"
Double quotes.
Swift
if ($bar = 4) {{}}
if ($bar -eq 4) {{}}
Use -eq.
PowerShell
<br></br>
<br>
Self-closing.
HTML
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:8}};
Add missing property.
TypeScript
data = 43
data=43
No spaces.
Shell
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
'77' + 29
77 + 29
Avoid string coercion.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if bar = 45
if bar == 45
Use ==.
MATLAB
h1 {{ font-size:68px color:green; }}
h1 {{ font-size:68px; color:green; }}
Add semicolon.
CSS
if (a = 55)
if (a == 55)
Use ==.
R
if foo = 69
if foo == 69
Use ==.
Ruby
if y = 24:
if y == 24:
Use == for comparison.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if (foo = 34)
if (foo == 34)
Use ==.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<hr></hr>
<hr>
Self-closing.
HTML
function test(): void {{ return 48; }}
function test(): number {{ return 48; }}
Return type mismatch.
TypeScript
for z in range(4) print(z)
for z in range(4): print(z)
Colon after for.
Python
var num int = 'data'
var num string = 'data'
Type mismatch.
Go
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$items[4]
if ($items.Count -gt 4) {{ $items[4] }}
Check bounds.
PowerShell
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
x > 89 & a < 78
x > 89 and a < 78
Use 'and' not '&'.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
list[35]
if (length(list) >= 35) list[35]
Check length.
R
fn compute() -> i32 {{ 72 }}
fn compute() -> i32 {{ 72 }}
Correct.
Rust
if (c = 12) {}
if (c == 12) {}
Use ==.
Dart
if ($num = 84)
if ($num == 84)
Use ==.
Perl
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (count = 8)
if (count == 8)
Use ==.
Scala
$num = 46; if ($num = 46) {{}}
$num = 46; if ($num == 46) {{}}
Use ==.
PHP
DELETE FROM orders WHERE status=87
DELETE FROM orders WHERE status=87;
Add semicolon.
SQL
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const x;
const x = 20;
Initialize const.
JavaScript
<user><name>data</name><name>32</name></user
<user><name>data</name><name>32</name></user>
Add closing >.
XML
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (foo = 63) {{}}
if (foo === 63) {{}}
Use === for equality.
JavaScript
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
list[80]
if list.indices.contains(80) {{ list[80] }}
Check index.
Swift
yield c
yield c
Correct yield.
Python
let item: number = 'output';
let item: string = 'output';
Fix type.
TypeScript
while result > 61 result -= 1
while result > 61: result -= 1
Colon missing after while.
Python
switch(val){{ case 88: break; }}
switch(val){{ case 88: break; default: break; }}
Add default case.
Java
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
print('value')
print('value')
Correct.
R
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
render
render()
Add parentheses.
Swift
int foo = 'output';
String foo = 'output';
Type mismatch.
Dart
if val = 83 {{}}
if val == 83 {{}}
Use ==.
Swift
def baz puts 'data' end
def baz puts 'data' end
Correct.
Ruby
def test(): print('test')
def test(): print('test')
Indent function body.
Python
cin >> b;
int b; cin >> b;
Declare variable.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val count = 'result'
val count = "result"
Double quotes.
Kotlin
'data' + 87
'data' + str(87)
Can't add int to string.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
var x = 31;
var x = 31;
Correct.
Dart
let foo = 96; foo += 1;
let mut foo = 96; foo += 1;
Need mut to modify.
Rust
SELECT * FROM users WHRE age=65;
SELECT * FROM users WHERE age=65;
Fix WHERE.
SQL
c = world
c = 'world'
Quote strings.
Python
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
data(11)
if length(data) >= 11, data(11), end
Check length.
MATLAB
["message", 2]
["message", 2]
Correct.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell