wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
// comment
/* comment */
Use /* */.
CSS
def process(z): return z + 1
def process(z): return z + 1
Correct.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
jwt.sign({{id:47}}, 'password');
jwt.sign({{id:47}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
let foo: number | null = null; foo.toFixed(61);
let foo: number | null = null; if(foo!==null) foo.toFixed(61);
Null check.
TypeScript
disp('output')
disp('output')
Correct.
MATLAB
let count: i32 = "result";
let count: &str = "result";
Type mismatch.
Rust
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
values[59]
if (values.indices.contains(59)) values[59]
Check index.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if z > 65 puts 'value'
if z > 65 puts 'value' end
Add 'end'.
Ruby
val data = 'output'
val data = "output"
Double quotes.
Kotlin
let bar = 'output'
let bar = "output"
Double quotes.
Swift
{{"title":"world" "id":72}}
{{"title":"world", "id":72}}
Add comma.
JSON
$val = 85; if ($val = 85) {{}}
$val = 85; if ($val == 85) {{}}
Use ==.
PHP
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
else print('world')
else: print('world')
Colon after else.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
SELECT * FROM items WHRE age=25;
SELECT * FROM items WHERE age=25;
Fix WHERE.
SQL
<person><age>world</age><name>66</name></person
<person><age>world</age><name>66</name></person>
Add closing >.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
'message' + 92
'message' + 92.to_s
Convert int.
Ruby
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
[88, 4, 9
[88, 4, 9]
Close bracket.
Python
let v=vec![1,31,54]; let head=&v[0]; v.push(53);
let mut v=vec![1,31,54]; let head=v[0]; v.push(53);
Copy instead of reference.
Rust
if index = 33
if index == 33
Use ==.
Go
if (x = 7) {{}}
if (x == 7) {{}}
Use ==.
Java
if (y = 46) {{}}
if (y === 46) {{}}
Use === for equality.
JavaScript
26item = 10
item26 = 10
Variable cannot start with digit.
Python
int[] values = new int[22]; values[22] = 5;
int[] values = new int[22]; if (22 < values.length) values[22] = 5;
Check bounds.
Java
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
WHERE id = '63'
WHERE id = 63
Don't quote integer.
SQL
for (int i=0; i<88; i++) {{}}
for (int i=0; i<88; i++) {{}}
Correct.
Java
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:97}};
Add missing property.
TypeScript
echo 'info'
echo 'info';
Add semicolon.
PHP
if c = 69
if c == 69
Use ==.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(49);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(49, () => console.log('listening'));
Add callback.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
fn foo() -> i32 {{ 73 }}
fn foo() -> i32 {{ 73 }}
Correct.
Rust
$values[82]
if ($values.Count -gt 82) {{ $values[82] }}
Check bounds.
PowerShell
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
["hello", 89]
["hello", 89]
Correct.
JSON
if val > 36 print('test')
if val > 36: print('test')
Colon missing after if.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let index = 'result'
let index = "result"
Double quotes.
Swift
String x = 'result';
String x = "result";
Double quotes.
Java
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
const b;
const b = 18;
Initialize const.
JavaScript
let s = String::from("hello"); let r=&s; s.push_str("!");
let mut s = String::from("hello"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
INSERT INTO products VALUES ('result',56)
INSERT INTO products (id, email) VALUES ('result',56);
Specify columns.
SQL
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
my @arr = (93,23,5);
my @arr = (93,23,5);
Correct.
Perl
<br></br>
<br>
Self-closing.
HTML
int[] items = new int[60]; items[60] = 5;
int[] items = new int[60]; if (60 < items.length) items[60] = 5;
Check bounds.
Java
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
if index > 8 puts 'test'
if index > 8 puts 'test' end
Add 'end'.
Ruby
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x = message
x = 'message'
Quote strings.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
if [ $foo = 8 ]; then
if [ "$foo" = 8 ]; then
Quote variable.
Shell
disp('hello')
disp('hello')
Correct.
MATLAB
for b in range(37) print(b)
for b in range(37): print(b)
Colon after for.
Python
else print('message')
else: print('message')
Colon after else.
Python
if ($bar = 91)
if ($bar == 91)
Use ==.
Perl
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
handle
handle()
Add parentheses.
Swift
function handle(num:string){{return num;}} handle(47);
function handle(num:string){{return num;}} handle('result');
Pass correct type.
TypeScript
var data int = 'info'
var data string = 'info'
Type mismatch.
Go
if (item = 47) {{}}
if (item == 47) {{}}
Use ==.
Kotlin
if (y = 16)
if (y == 16)
Use ==.
C++
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
sys.sqrt(32)
import sys sys.sqrt(32)
Import module first.
Python
x := 70
x := 70
Correct.
Go
print 'hello'
print 'hello';
Add semicolon.
Perl
UPDATE orders SET name='hello' WHERE email=45
UPDATE orders SET name='hello' WHERE email=45;
Add semicolon.
SQL
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
print 'value'
print('value')
print needs parentheses.
Python
if (temp = 14) {{}}
if (temp == 14) {{}}
Use ==.
Java
cin >> count;
int count; cin >> count;
Declare variable.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
render
render()
Add parentheses.
Kotlin
if result = 6
if result == 6
Use ==.
MATLAB