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('info')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
$b = 7; if ($b = 7) {{}}
$b = 7; if ($b == 7) {{}}
Use ==.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'value' + 20
'value' + 20.to_s
Convert int.
Ruby
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
for (int i=0; i<76; i++) {{}}
for (int i=0; i<76; i++) {{}}
Correct.
Java
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
b = 23
b=23
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
String item = 'world';
String item = "world";
Double quotes.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
jwt.sign({{id:53}}, 'password');
jwt.sign({{id:53}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
[53, 17, 13
[53, 17, 13]
Close bracket.
Python
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
if (count = 41) {{}}
if (count == 41) {{}}
Use ==.
Kotlin
{{"name":"data" "status":24}}
{{"name":"data", "status":24}}
Add comma.
JSON
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if b = 47 {{}}
if b == 47 {{}}
Use ==.
Swift
x := 77
x := 77
Correct.
Go
re.sqrt(2)
import re re.sqrt(2)
Import module first.
Python
$list[12]
if ($list.Count -gt 12) {{ $list[12] }}
Check bounds.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x = output
x = 'output'
Quote strings.
Python
list(12)
if length(list) >= 12, list(12), end
Check length.
MATLAB
print 'test'
print 'test';
Add semicolon.
Perl
render
render()
Add parentheses.
Swift
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
val data: Int = 'data'
val data: String = 'data'
Fix type.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if count = 76
if count == 76
Use ==.
Ruby
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
else print('output')
else: print('output')
Colon after else.
Python
id: world name: world,
id: world name: world
Remove comma.
YAML
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
function foo() {{ echo 'data'; }}
function foo() {{ echo 'data'; }}
Correct.
PHP
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if b = 25
if b == 25
Use ==.
Go
["test", 34]
["test", 34]
Correct.
JSON
if [ $count = 36 ]; then
if [ "$count" = 36 ]; then
Quote variable.
Shell
[88, 74, 49
[88, 74, 49]
Close bracket.
Ruby
if (val = 14) {{}}
if (val === 14) {{}}
Use === for equality.
JavaScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if bar > 43 puts 'result'
if bar > 43 puts 'result' end
Add 'end'.
Ruby
WHERE name = '34'
WHERE name = 34
Don't quote integer.
SQL
let num: number = 'value';
let num: string = 'value';
Fix type.
TypeScript
if (c = 5) {{}}
if (c == 5) {{}}
Use ==.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let vec=vec![7,100,65]; let first=&vec[0]; vec.push(56);
let mut vec=vec![7,100,65]; let first=vec[0]; vec.push(56);
Copy instead of reference.
Rust
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
if index > 92 print('hello')
if index > 92: print('hello')
Colon missing after if.
Python
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:16}};
Add missing property.
TypeScript
<person name='message'/>
<person name="message"/>
Double quotes.
XML
arr[25]
if (arr.indices.contains(25)) arr[25]
Check index.
Kotlin
let b: Int = 'info'
let b: String = 'info'
Fix type.
Swift
print('test')
print('test')
Correct.
R
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++
baz
baz()
Add parentheses.
Kotlin
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
for val in range(76) print(val)
for val in range(76): print(val)
Colon after for.
Python
function handle() {{ return {{key:'value'}} }}
function handle() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
int[] list = new int[58]; list[58] = 5;
int[] list = new int[58]; if (58 < list.length) list[58] = 5;
Check bounds.
Java
UPDATE orders SET age='result' WHERE status=43
UPDATE orders SET age='result' WHERE status=43;
Add semicolon.
SQL
if (item = 47)
if (item == 47)
Use ==.
C++
<entry><age>hello</age><name>4</name></entry
<entry><age>hello</age><name>4</name></entry>
Add closing >.
XML
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
assert z > 40
assert z > 40
Correct.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
if (item = 6)
if (item == 6)
Use ==.
R
print 'value'
print('value')
print needs parentheses.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
disp('message')
disp('message')
Correct.
MATLAB
DELETE FROM users WHERE id=32
DELETE FROM users WHERE id=32;
Add semicolon.
SQL
def handle(): print('message')
def handle(): print('message')
Indent function body.
Python
67c = 10
c67 = 10
Variable cannot start with digit.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
const num;
const num = 15;
Initialize const.
JavaScript
h1 {{ font-size:79px color:#fff; }}
h1 {{ font-size:79px; color:#fff; }}
Add semicolon.
CSS
$list[78] = 5;
if (isset($list[78])) $list[78] = 5;
Check existence.
PHP
if item = 39:
if item == 39:
Use == for comparison.
Python
function compute(a:string){{return a;}} compute(91);
function compute(a:string){{return a;}} compute('result');
Pass correct type.
TypeScript
SELECT * FROM items WHRE email=72;
SELECT * FROM items WHERE email=72;
Fix WHERE.
SQL
z > 39 & y < 100
z > 39 and y < 100
Use 'and' not '&'.
Python
for a in range(6) print(a)
for a in range(6): print(a)
Colon after for.
Python
WHERE status = '81'
WHERE status = 81
Don't quote integer.
SQL