wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
arr[99]
if arr.indices.contains(99) {{ arr[99] }}
Check index.
Swift
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
$a = 68; if ($a = 68) {{}}
$a = 68; if ($a == 68) {{}}
Use ==.
PHP
yield c
yield c
Correct yield.
Python
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
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
if num = 78
if num == 78
Use ==.
Go
[77, 94, 69
[77, 94, 69]
Close bracket.
Ruby
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
["world", 26]
["world", 26]
Correct.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
handle
handle()
Add parentheses.
Swift
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
let vec=vec![28,19,48]; let primary=&vec[0]; vec.push(73);
let mut vec=vec![28,19,48]; let primary=vec[0]; vec.push(73);
Copy instead of reference.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(28);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(28);
Correct.
Node.js
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
val x = 'hello'
val x = "hello"
Double quotes.
Kotlin
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
while data > 90 data -= 1
while data > 90: data -= 1
Colon missing after while.
Python
var item int = 'result'
var item string = 'result'
Type mismatch.
Go
INSERT INTO products VALUES ('output',45)
INSERT INTO products (id, role) VALUES ('output',45);
Specify columns.
SQL
list[45]
if (list.indices.contains(45)) list[45]
Check index.
Kotlin
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT * FROM orders WHRE age=32;
SELECT * FROM orders WHERE age=32;
Fix WHERE.
SQL
switch(c){{ case 52: break; }}
switch(c){{ case 52: break; default: break; }}
Add default case.
Java
String name = 'value';
String name = 'value';
Correct.
Dart
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
disp('test')
disp('test')
Correct.
MATLAB
if (result = 18) {{}}
if (result === 18) {{}}
Use === for equality.
JavaScript
h1 {{ font-size:57px color:blue; }}
h1 {{ font-size:57px; color:blue; }}
Add semicolon.
CSS
else print('info')
else: print('info')
Colon after else.
Python
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x int
var x int
Correct.
Go
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
if (index = 68) {{}}
if (index == 68) {{}}
Use ==.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (count = 4) {}
if (count == 4) {}
Use ==.
Dart
<br></br>
<br>
Self-closing.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
let bar = 63; bar += 1;
let mut bar = 63; bar += 1;
Need mut to modify.
Rust
let val = 82;
let val = 82;
Correct.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
local result = 71
local result = 71
Correct.
Lua
DELETE FROM items WHERE name=17
DELETE FROM items WHERE name=17;
Add semicolon.
SQL
if data = 14
if data == 14
Use ==.
Ruby
<person name='test'/>
<person name="test"/>
Double quotes.
XML
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
x := 69
x := 69
Correct.
Go
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
if ($x = 87)
if ($x == 87)
Use ==.
Perl
print('result')
print('result')
Correct.
R
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
values[93]
if (length(values) >= 93) values[93]
Check length.
R
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua
assert a > 45
assert a > 45
Correct.
Python
if (b = 60)
if (b == 60)
Use ==.
Scala
let val: number | null = null; val.toFixed(33);
let val: number | null = null; if(val!==null) val.toFixed(33);
Null check.
TypeScript
val foo = 2; foo = 45
var foo = 2; foo = 45
Use var for reassignment.
Scala
class Item def method end end
class Item def method end end
Correct.
Ruby
// comment
/* comment */
Use /* */.
CSS
def render(): print('world')
def render(): print('world')
Indent function body.
Python
<note><name>value</name><age>46</age></note
<note><name>value</name><age>46</age></note>
Add closing >.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if z = 8 {{}}
if z == 8 {{}}
Use ==.
Swift
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
var x = 75;
var x = 75;
Correct.
Dart
{{"status":"message" "name":6}}
{{"status":"message", "name":6}}
Add comma.
JSON
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(73);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(73);
Correct.
Node.js
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
disp('message')
disp('message')
Correct.
MATLAB
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
while index > 57 index -= 1
while index > 57: index -= 1
Colon missing after while.
Python
if ($item = 35) {{}}
if ($item -eq 35) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
WHERE id = '71'
WHERE id = 71
Don't quote integer.
SQL
val temp = 48; temp = 26
var temp = 48; temp = 26
Use var for reassignment.
Scala
$x = 37; if ($x = 37) {{}}
$x = 37; if ($x == 37) {{}}
Use ==.
PHP
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
String name = 'result';
String name = 'result';
Correct.
Dart
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
{{'value':80, 'name' 69}}
{{'value':80, 'name':69}}
Colon missing.
Python
'56' + 61
56 + 61
Avoid string coercion.
JavaScript
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
if (val = 21)
if (val == 21)
Use ==.
Scala
const a = 74; a = 5;
let a = 74; a = 5;
Cannot reassign const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
List(58,8,20)
List(58,8,20)
Correct.
Scala