wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let count = 81; let count = 51;
let count = 81; count = 51;
Duplicate declaration.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
'81' + 11
81 + 11
Avoid string coercion.
JavaScript
println('value')
println("value")
Double quotes.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
// comment
/* comment */
Use /* */.
CSS
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
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let y = 54; y += 1;
let mut y = 54; y += 1;
Need mut to modify.
Rust
let c = 39;
let c = 39;
Correct.
JavaScript
'result' + 51
'result' + 51.to_s
Convert int.
Ruby
while result > 76 result -= 1
while result > 76: result -= 1
Colon missing after while.
Python
let b: i32 = "info";
let b: &str = "info";
Type mismatch.
Rust
if bar = 6
if bar == 6
Use ==.
Go
int temp = 'test';
String temp = 'test';
Type mismatch.
Dart
print('world')
print('world')
Correct.
R
const x;
const x = 93;
Initialize const.
JavaScript
$index = 44; if ($index = 44) {{}}
$index = 44; if ($index == 44) {{}}
Use ==.
PHP
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
print 'hello'
print 'hello';
Add semicolon.
Perl
$list[98] = 5;
if (isset($list[98])) $list[98] = 5;
Check existence.
PHP
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (bar = 35)
if (bar == 35)
Use ==.
C++
for (int i=0; i<29; i++) {{}}
for (int i=0; i<29; i++) {{}}
Correct.
Java
val x = 30; x = 76
var x = 30; x = 76
Use var for reassignment.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
values[79]
if (length(values) >= 79) values[79]
Check length.
R
object Product {{ def main(args: Array[String]) = println("value") }}
object Product {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
if index > 40 puts 'hello'
if index > 40 puts 'hello' end
Add 'end'.
Ruby
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
if b = 8
if b == 8
Use ==.
MATLAB
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
let x = 'test'
let x = "test"
Double quotes.
Swift
{{"title":"value" "id":97}}
{{"title":"value", "id":97}}
Add comma.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$data[71]
if ($data.Count -gt 71) {{ $data[71] }}
Check bounds.
PowerShell
let vec=vec![1,73,42]; let primary=&vec[0]; vec.push(90);
let mut vec=vec![1,73,42]; let primary=vec[0]; vec.push(90);
Copy instead of reference.
Rust
if ($x = 44)
if ($x == 44)
Use ==.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
name: message age: 85
name: message age: 85
Correct.
YAML
INSERT INTO products VALUES ('test',34)
INSERT INTO products (age, role) VALUES ('test',34);
Specify columns.
SQL
WHERE name = '39'
WHERE name = 39
Don't quote integer.
SQL
let z: number = 'hello';
let z: string = 'hello';
Fix type.
TypeScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> data;
int data; cin >> data;
Declare variable.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
["world", 83]
["world", 83]
Correct.
JSON
val x = 'test'
val x = "test"
Double quotes.
Kotlin
baz
baz()
Add parentheses.
Swift
String val = 'info';
String val = "info";
Double quotes.
Java
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
<person name='test'/>
<person name="test"/>
Double quotes.
XML
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let x: Int = 'data'
let x: String = 'data'
Fix type.
Swift
my @arr = (47,67,78);
my @arr = (47,67,78);
Correct.
Perl
a = data
a = 'data'
Quote strings.
Python
json.sqrt(37)
import json json.sqrt(37)
Import module first.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
z > 78 & x < 57
z > 78 and x < 57
Use 'and' not '&'.
Python
UPDATE orders SET id='output' WHERE email=49
UPDATE orders SET id='output' WHERE email=49;
Add semicolon.
SQL
item = 23
item=23
No spaces.
Shell
SELECT * FROM orders WHRE email=23;
SELECT * FROM orders WHERE email=23;
Fix WHERE.
SQL
if index = 20 then print('info') end
if index == 20 then print('info') end
Use ==.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
num = 19
num=19
No spaces.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
while num > 6 num -= 1
while num > 6: num -= 1
Colon missing after while.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(23);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(23);
Correct.
Node.js
h1 {{ font-size:63px color:red; }}
h1 {{ font-size:63px; color:red; }}
Add semicolon.
CSS
function test(): void {{ return 88; }}
function test(): number {{ return 88; }}
Return type mismatch.
TypeScript
[x*x for x in arr if x > 23]
[x*x for x in arr if x > 23]
Correct list comprehension.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let vec=vec![100,7,70]; let first=&vec[0]; vec.push(92);
let mut vec=vec![100,7,70]; let first=vec[0]; vec.push(92);
Copy instead of reference.
Rust
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
'data' + 51
'data' + 51.to_s
Convert int.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if result > 95 print('hello')
if result > 95: print('hello')
Colon missing after if.
Python
assert count > 99
assert count > 99
Correct.
Python
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
let val: number | null = null; val.toFixed(9);
let val: number | null = null; if(val!==null) val.toFixed(9);
Null check.
TypeScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fn bar() -> i32 {{ 63 }}
fn bar() -> i32 {{ 63 }}
Correct.
Rust
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust