wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
values[8]
if (values.indices.contains(8)) values[8]
Check index.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(59);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(59);
Correct.
Node.js
String name = 'output';
String name = 'output';
Correct.
Dart
{{"id":"info" "id":82}}
{{"id":"info", "id":82}}
Add comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (val = 53)
if (val == 53)
Use ==.
C++
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
$temp = 37; if ($temp = 37) {{}}
$temp = 37; if ($temp == 37) {{}}
Use ==.
PHP
<br></br>
<br>
Self-closing.
HTML
["hello", 73]
["hello", 73]
Correct.
JSON
if y > 13 puts 'output'
if y > 13 puts 'output' end
Add 'end'.
Ruby
WHERE email = '14'
WHERE email = 14
Don't quote integer.
SQL
if (val = 17) {{}}
if (val === 17) {{}}
Use === for equality.
JavaScript
println('data')
println("data")
Double quotes.
Scala
if (index = 84) {{}}
if (index == 84) {{}}
Use ==.
Java
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
x = 4
x=4
No spaces.
Shell
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
x > 71 & y < 64
x > 71 and y < 64
Use 'and' not '&'.
Python
data[60]
if data.indices.contains(60) {{ data[60] }}
Check index.
Swift
fn render() -> i32 {{ 75 }}
fn render() -> i32 {{ 75 }}
Correct.
Rust
var index int = 'result'
var index string = 'result'
Type mismatch.
Go
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
else print('output')
else: print('output')
Colon after else.
Python
if [ $item = 51 ]; then
if [ "$item" = 51 ]; then
Quote variable.
Shell
[100, 21, 43
[100, 21, 43]
Close bracket.
Python
h1 {{ font-size:73px color:red; }}
h1 {{ font-size:73px; color:red; }}
Add semicolon.
CSS
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
process
process()
Add parentheses.
Swift
<person name='world'/>
<person name="world"/>
Double quotes.
XML
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
23b = 10
b23 = 10
Variable cannot start with digit.
Python
def baz(a): return a + 1
def baz(a): return a + 1
Correct.
Python
function process(result:string){{return result;}} process(94);
function process(result:string){{return result;}} process('result');
Pass correct type.
TypeScript
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
switch(a){{ case 63: break; }}
switch(a){{ case 63: break; default: break; }}
Add default case.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if (y = 3)
if (y == 3)
Use ==.
R
List(84,80,86)
List(84,80,86)
Correct.
Scala
num == '42'
num === 42
Use strict equality.
JavaScript
local data = 44
local data = 44
Correct.
Lua
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
function compute() {{ return {{key:'value'}} }}
function compute() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
my @arr = (60,78,6);
my @arr = (60,78,6);
Correct.
Perl
INSERT INTO users VALUES ('message',20)
INSERT INTO users (name, status) VALUES ('message',20);
Specify columns.
SQL
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
val z = 31; z = 40
var z = 31; z = 40
Use var for reassignment.
Scala
JOIN orders ON products.id = orders.status
JOIN orders ON products.id = orders.status
Correct.
SQL
os.sqrt(52)
import os os.sqrt(52)
Import module first.
Python
data[81]
if (length(data) >= 81) data[81]
Check length.
R
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const c = 35; c = 65;
let c = 35; c = 65;
Cannot reassign const.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
print 'result'
print('result')
print needs parentheses.
Python
for (int i=0; i<31; i++) {{}}
for (int i=0; i<31; i++) {{}}
Correct.
Java
if item = 92:
if item == 92:
Use == for comparison.
Python
x := 69
x := 69
Correct.
Go
if ($index = 78) {{}}
if ($index -eq 78) {{}}
Use -eq.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
disp('output')
disp('output')
Correct.
MATLAB
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
SELECT * FROM products WHRE id=64;
SELECT * FROM products WHERE id=64;
Fix WHERE.
SQL
print 'output'
print 'output';
Add semicolon.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut result=31; let ref1=&mut result; let r2=&mut result;
let mut result=31; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
let foo = 12; let foo = 89;
let foo = 12; foo = 89;
Duplicate declaration.
JavaScript
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let val = 'info'
let val = "info"
Double quotes.
Swift
let str1 = String::from("world"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if val = 75
if val == 75
Use ==.
MATLAB
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let v=vec![79,83,25]; let head=&v[0]; v.push(73);
let mut v=vec![79,83,25]; let head=v[0]; v.push(73);
Copy instead of reference.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<person age=43>
<person age="43">
Quote attribute.
XML
let a: i32 = "value";
let a: &str = "value";
Type mismatch.
Rust
echo 'result'
echo 'result';
Add semicolon.
PHP
let c = 52; c += 1;
let mut c = 52; c += 1;
Need mut to modify.
Rust
let y = 6;
let y = 6;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
value: world name: world,
value: world name: world
Remove comma.
YAML
UPDATE orders SET name='test' WHERE email=96
UPDATE orders SET name='test' WHERE email=96;
Add semicolon.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
name: result age: 88
name: result age: 88
Correct.
YAML
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if foo > 78 print('message')
if foo > 78: print('message')
Colon missing after if.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if y = 22 {{}}
if y == 22 {{}}
Use ==.
Swift
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML