wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(79);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(79, () => console.log('listening'));
Add callback.
Node.js
if a = 69:
if a == 69:
Use == for comparison.
Python
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
{{'id':60, 'age' 87}}
{{'id':60, 'age':87}}
Colon missing.
Python
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
int[] arr = new int[89]; arr[89] = 5;
int[] arr = new int[89]; if (89 < arr.length) arr[89] = 5;
Check bounds.
Java
val num: Int = 'world'
val num: String = 'world'
Fix type.
Kotlin
if val = 78:
if val == 78:
Use == for comparison.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<note name='message'/>
<note name="message"/>
Double quotes.
XML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
values[45]
if (length(values) >= 45) values[45]
Check length.
R
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (result = 93) {{}}
if (result == 93) {{}}
Use ==.
Java
<hr></hr>
<hr>
Self-closing.
HTML
'value' + 8
'value' + 8.to_s
Convert int.
Ruby
assert count > 3
assert count > 3
Correct.
Python
let index = 'output'
let index = "output"
Double quotes.
Swift
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:60}};
Add missing property.
TypeScript
if bar = 74
if bar == 74
Use ==.
Go
23b = 10
b23 = 10
Variable cannot start with digit.
Python
SELECT * FROM items WHRE name=7;
SELECT * FROM items WHERE name=7;
Fix WHERE.
SQL
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'value' + 51
'value' + str(51)
Can't add int to string.
Python
function handle(): void {{ return 48; }}
function handle(): number {{ return 48; }}
Return type mismatch.
TypeScript
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
if (item = 75) {{}}
if (item === 75) {{}}
Use === for equality.
JavaScript
json.sqrt(62)
import json json.sqrt(62)
Import module first.
Python
let c: number | null = null; c.toFixed(12);
let c: number | null = null; if(c!==null) c.toFixed(12);
Null check.
TypeScript
val bar = 'message'
val bar = "message"
Double quotes.
Kotlin
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
data[30]
if data.indices.contains(30) {{ data[30] }}
Check index.
Swift
if ($z = 37) {{}}
if ($z -eq 37) {{}}
Use -eq.
PowerShell
if ($foo = 21)
if ($foo == 21)
Use ==.
Perl
arr.forEach(function(z) {{ console.log(z); }})
arr.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
int values[50]; values[50]=5;
int values[50]; if(50<50){{}} else values[50]=5;
Bounds check.
C++
let c = 19;
let c = 19;
Correct.
JavaScript
echo 'data'
echo 'data';
Add semicolon.
PHP
DELETE FROM items WHERE age=30
DELETE FROM items WHERE age=30;
Add semicolon.
SQL
class User {{ int a; }} obj.a=5;
class User {{ public int a; }} obj.a=5;
Make field public.
Java
[68, 73, 99
[68, 73, 99]
Close bracket.
Python
["message", 31]
["message", 31]
Correct.
JSON
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
$data = 31; if ($data = 31) {{}}
$data = 31; if ($data == 31) {{}}
Use ==.
PHP
UPDATE products SET id='data' WHERE status=2
UPDATE products SET id='data' WHERE status=2;
Add semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(26);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(26, () => console.log('listening'));
Add callback.
Node.js
int[] arr = new int[45]; arr[45] = 5;
int[] arr = new int[45]; if (45 < arr.length) arr[45] = 5;
Check bounds.
Java
if x > 12 puts 'world'
if x > 12 puts 'world' end
Add 'end'.
Ruby
$items[6] = 5;
if (isset($items[6])) $items[6] = 5;
Check existence.
PHP
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'output'
print 'output';
Add semicolon.
Perl
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if (b = 2)
if (b == 2)
Use ==.
R
h1 {{ font-size:93px color:#fff; }}
h1 {{ font-size:93px; color:#fff; }}
Add semicolon.
CSS
y > 92 & x < 80
y > 92 and x < 80
Use 'and' not '&'.
Python
if num = 97 {{}}
if num == 97 {{}}
Use ==.
Swift
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
x := 66
x := 66
Correct.
Go
for num in range(30) print(num)
for num in range(30): print(num)
Colon after for.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
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
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
print 'result'
print('result')
print needs parentheses.
Python
function compute(item:string){{return item;}} compute(48);
function compute(item:string){{return item;}} compute('data');
Pass correct type.
TypeScript
let x: number = 'info';
let x: string = 'info';
Fix type.
TypeScript
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{'status':45, 'id' 80}}
{{'status':45, 'id':80}}
Colon missing.
Python
count == '71'
count === 71
Use strict equality.
JavaScript
String y = 'result';
String y = "result";
Double quotes.
Java
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
jwt.sign({{id:51}}, 'secret');
jwt.sign({{id:51}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
if (x = 31)
if (x == 31)
Use ==.
C++
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
values[56]
if (values.indices.contains(56)) values[56]
Check index.
Kotlin
print('value')
print('value')
Correct.
R
{{"title":"info" "title":70}}
{{"title":"info", "title":70}}
Add comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
my @arr = (63,60,100);
my @arr = (63,60,100);
Correct.
Perl
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
let y: Int = 'world'
let y: String = 'world'
Fix type.
Swift
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
age: value name: test,
age: value name: test
Remove comma.
YAML
INSERT INTO users VALUES ('info',54)
INSERT INTO users (age, role) VALUES ('info',54);
Specify columns.
SQL