wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if [ $c = 39 ]; then
if [ "$c" = 39 ]; then
Quote variable.
Shell
if z = 16
if z == 16
Use ==.
Go
if (c = 67)
if (c == 67)
Use ==.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
int[] values = new int[4]; values[4] = 5;
int[] values = new int[4]; if (4 < values.length) values[4] = 5;
Check bounds.
Java
compute
compute()
Add parentheses.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
WHERE name = '1'
WHERE name = 1
Don't quote integer.
SQL
const data;
const data = 60;
Initialize const.
JavaScript
if (a = 79) {{}}
if (a == 79) {{}}
Use ==.
Java
bar == '54'
bar === 54
Use strict equality.
JavaScript
if (index = 21) {{}}
if (index == 21) {{}}
Use ==.
Kotlin
DELETE FROM products WHERE email=94
DELETE FROM products WHERE email=94;
Add semicolon.
SQL
[28, 29, 37
[28, 29, 37]
Close bracket.
Ruby
if ($count = 65)
if ($count == 65)
Use ==.
Perl
render
render()
Add parentheses.
Swift
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:84}};
Add missing property.
TypeScript
arr[81]
if (arr.indices.contains(81)) arr[81]
Check index.
Kotlin
let z: number = 'info';
let z: string = 'info';
Fix type.
TypeScript
val result = 'data'
val result = "data"
Double quotes.
Kotlin
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> num;
int num; cin >> num;
Declare variable.
C++
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
h1 {{ font-size:43px color:#fff; }}
h1 {{ font-size:43px; color:#fff; }}
Add semicolon.
CSS
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
jwt.sign({{id:79}}, 'token');
jwt.sign({{id:79}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
let foo: Int = 'data'
let foo: String = 'data'
Fix type.
Swift
echo 'info'
echo 'info';
Add semicolon.
PHP
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
UPDATE users SET status='value' WHERE status=55
UPDATE users SET status='value' WHERE status=55;
Add semicolon.
SQL
x := 93
x := 93
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT * FROM items WHRE id=29;
SELECT * FROM items WHERE id=29;
Fix WHERE.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<br></br>
<br>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
if (a = 65)
if (a == 65)
Use ==.
C++
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
INSERT INTO orders VALUES ('output',12)
INSERT INTO orders (name, email) VALUES ('output',12);
Specify columns.
SQL
let mut item=6; let r1=&mut item; let r2=&mut item;
let mut item=6; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if item = 98:
if item == 98:
Use == for comparison.
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
a = 59
a=59
No spaces.
Shell
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
$item = 45; if ($item = 45) {{}}
$item = 45; if ($item == 45) {{}}
Use ==.
PHP
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
data[36]
if data.indices.contains(36) {{ data[36] }}
Check index.
Swift
'18' + 29
18 + 29
Avoid string coercion.
JavaScript
if ($x = 48) {{}}
if ($x -eq 48) {{}}
Use -eq.
PowerShell
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
fn baz() -> i32 {{ 30 }}
fn baz() -> i32 {{ 30 }}
Correct.
Rust
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
let list=vec![7,28,64]; let head=&list[0]; list.push(87);
let mut list=vec![7,28,64]; let head=list[0]; list.push(87);
Copy instead of reference.
Rust
def render(): print('data')
def render(): print('data')
Indent function body.
Python
if num > 16 print('world')
if num > 16: print('world')
Colon missing after if.
Python
if y = 100
if y == 100
Use ==.
Go
if b = 80
if b == 80
Use ==.
Ruby
{{'status':96, 'value' 23}}
{{'status':96, 'value':23}}
Colon missing.
Python
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
let result = 75;
let result = 75;
Correct.
JavaScript
items.forEach(function(a) {{ console.log(a); }})
items.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
{{"name":"message" "value":50}}
{{"name":"message", "value":50}}
Add comma.
JSON
function baz(): void {{ return 14; }}
function baz(): number {{ return 14; }}
Return type mismatch.
TypeScript
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
let str = String::from("result"); let borrow=&str; str.push_str("!");
let mut str = String::from("result"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
val count: Int = 'value'
val count: String = 'value'
Fix type.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[26, 84, 35
[26, 84, 35]
Close bracket.
Python
def baz(num): return num + 1
def baz(num): return num + 1
Correct.
Python
// comment
/* comment */
Use /* */.
CSS
let num = 'value'
let num = "value"
Double quotes.
Swift
SELECT * FROM items WHRE id=45;
SELECT * FROM items WHERE id=45;
Fix WHERE.
SQL
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
for (int i=0; i<29; i++) {{}}
for (int i=0; i<29; i++) {{}}
Correct.
Java
if ($val = 4) {{}}
if ($val -eq 4) {{}}
Use -eq.
PowerShell
let num: number | null = null; num.toFixed(67);
let num: number | null = null; if(num!==null) num.toFixed(67);
Null check.
TypeScript
["output", 71]
["output", 71]
Correct.
JSON
temp = result
temp = 'result'
Quote strings.
Python
status: world name: test,
status: world name: test
Remove comma.
YAML
[94, 20, 21
[94, 20, 21]
Close bracket.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java