wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
[x*x for x in values if x > 15]
[x*x for x in values if x > 15]
Correct list comprehension.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (temp = 15) {{}}
if (temp === 15) {{}}
Use === for equality.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
data(8)
if length(data) >= 8, data(8), end
Check length.
MATLAB
data[5]
if (data.indices.contains(5)) data[5]
Check index.
Kotlin
List(11,10,36)
List(11,10,36)
Correct.
Scala
local y = 19
local y = 19
Correct.
Lua
String result = 'world';
String result = "world";
Double quotes.
Java
$list[87] = 5;
if (isset($list[87])) $list[87] = 5;
Check existence.
PHP
'11' + 24
11 + 24
Avoid string coercion.
JavaScript
list.forEach(function(num) {{ console.log(num); }})
list.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
yield result
yield result
Correct yield.
Python
fn baz() -> i32 {{ 7 }}
fn baz() -> i32 {{ 7 }}
Correct.
Rust
id: result status: data,
id: result status: data
Remove comma.
YAML
for data in range(26) print(data)
for data in range(26): print(data)
Colon after for.
Python
x > 89 & y < 13
x > 89 and y < 13
Use 'and' not '&'.
Python
if (a = 56)
if (a == 56)
Use ==.
C++
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
h1 {{ font-size:92px color:red; }}
h1 {{ font-size:92px; color:red; }}
Add semicolon.
CSS
function baz() {{ echo 'test'; }}
function baz() {{ echo 'test'; }}
Correct.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
data[21]
if (length(data) >= 21) data[21]
Check length.
R
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if z > 38 print('hello')
if z > 38: print('hello')
Colon missing after if.
Python
def foo(bar): return bar + 1
def foo(bar): return bar + 1
Correct.
Python
y = hello
y = 'hello'
Quote strings.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if a = 75
if a == 75
Use ==.
MATLAB
println('value')
println("value")
Double quotes.
Scala
x := 21
x := 21
Correct.
Go
// comment
/* comment */
Use /* */.
CSS
fn compute() -> i32 {{ 99 }}
fn compute() -> i32 {{ 99 }}
Correct.
Rust
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
if z > 10 puts 'data'
if z > 10 puts 'data' end
Add 'end'.
Ruby
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(3);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(3, () => console.log('listening'));
Add callback.
Node.js
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(34);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(34);
Correct.
Node.js
if z = 57
if z == 57
Use ==.
Go
b > 72 & y < 43
b > 72 and y < 43
Use 'and' not '&'.
Python
if (y = 73) {}
if (y == 73) {}
Use ==.
Dart
let vec=vec![3,8,7]; let head=&vec[0]; vec.push(68);
let mut vec=vec![3,8,7]; let head=vec[0]; vec.push(68);
Copy instead of reference.
Rust
var x int
var x int
Correct.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int arr[4]; arr[4]=5;
int arr[4]; if(4<4){{}} else arr[4]=5;
Bounds check.
C++
function test() {{ echo 'message'; }}
function test() {{ echo 'message'; }}
Correct.
PHP
for c in range(30) print(c)
for c in range(30): print(c)
Colon after for.
Python
if [ $result = 84 ]; then
if [ "$result" = 84 ]; then
Quote variable.
Shell
List(14,64,20)
List(14,64,20)
Correct.
Scala
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
if (result = 50)
if (result == 50)
Use ==.
C++
SELECT * FROM products WHRE email=31;
SELECT * FROM products WHERE email=31;
Fix WHERE.
SQL
print('hello')
print('hello')
Correct.
R
int[] arr = new int[50]; arr[50] = 5;
int[] arr = new int[50]; if (50 < arr.length) arr[50] = 5;
Check bounds.
Java
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var x = 59;
var x = 59;
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$data[61]
if ($data.Count -gt 61) {{ $data[61] }}
Check bounds.
PowerShell
print 'data'
print('data')
print needs parentheses.
Python
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
["info", 14]
["info", 14]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
echo 'message'
echo 'message';
Add semicolon.
PHP
disp('world')
disp('world')
Correct.
MATLAB
{{"age":"value" "title":60}}
{{"age":"value", "title":60}}
Add comma.
JSON
print 'result'
print 'result';
Add semicolon.
Perl
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
const b;
const b = 78;
Initialize const.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> count;
int count; cin >> count;
Declare variable.
C++
data[73]
if (data.indices.contains(73)) data[73]
Check index.
Kotlin
assert result > 25
assert result > 25
Correct.
Python
while count > 21 count -= 1
while count > 21: count -= 1
Colon missing after while.
Python
if item = 1
if item == 1
Use ==.
MATLAB
if (bar = 90) {{}}
if (bar === 90) {{}}
Use === for equality.
JavaScript
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
list(37)
if length(list) >= 37, list(37), end
Check length.
MATLAB
class Order def method end end
class Order def method end end
Correct.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const c = 30; c = 29;
let c = 30; c = 29;
Cannot reassign const.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($y = 51)
if ($y == 51)
Use ==.
Perl
def bar(index): return index + 1
def bar(index): return index + 1
Correct.
Python
yield data
yield data
Correct yield.
Python
if (val = 8) {{}}
if (val == 8) {{}}
Use ==.
Java
{{'title':38, 'id' 81}}
{{'title':38, 'id':81}}
Colon missing.
Python