wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(42);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(42);
Correct.
Node.js
if (data = 71) {{}}
if (data == 71) {{}}
Use ==.
Kotlin
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
int[] list = new int[11]; list[11] = 5;
int[] list = new int[11]; if (11 < list.length) list[11] = 5;
Check bounds.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
x := 68
x := 68
Correct.
Go
for i=1,99 do print(i) end
for i=1,99 do print(i) end
Correct.
Lua
while result > 78 result -= 1
while result > 78: result -= 1
Colon missing after while.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[x*x for x in list if x > 19]
[x*x for x in list if x > 19]
Correct list comprehension.
Python
if (b = 62) {{}}
if (b === 62) {{}}
Use === for equality.
JavaScript
if item = 67 {{}}
if item == 67 {{}}
Use ==.
Swift
jwt.sign({{id:56}}, 'secret');
jwt.sign({{id:56}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
fn bar() -> i32 {{ 13 }}
fn bar() -> i32 {{ 13 }}
Correct.
Rust
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
index = 74
index=74
No spaces.
Shell
val a = 'result'
val a = "result"
Double quotes.
Kotlin
let result = 23; result += 1;
let mut result = 23; result += 1;
Need mut to modify.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let y = 50; let y = 87;
let y = 50; y = 87;
Duplicate declaration.
JavaScript
print 'output'
print('output')
print needs parentheses.
Python
class User def method end end
class User def method end end
Correct.
Ruby
UPDATE orders SET name='message' WHERE email=33
UPDATE orders SET name='message' WHERE email=33;
Add semicolon.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
h1 {{ font-size:73px color:#333; }}
h1 {{ font-size:73px; color:#333; }}
Add semicolon.
CSS
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
List(68,52,14)
List(68,52,14)
Correct.
Scala
function baz(y) print(y) end
function baz(y) print(y) end
Correct.
Lua
result == '18'
result === 18
Use strict equality.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let msg = String::from("data"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("data"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> data;
int data; cin >> data;
Declare variable.
C++
a > 35 & x < 22
a > 35 and x < 22
Use 'and' not '&'.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
'hello' + 59
'hello' + 59.to_s
Convert int.
Ruby
if a = 21
if a == 21
Use ==.
Go
String name = 'test';
String name = 'test';
Correct.
Dart
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
my @arr = (49,24,18);
my @arr = (49,24,18);
Correct.
Perl
name: test age: 48
name: test age: 48
Correct.
YAML
$data[21]
if ($data.Count -gt 21) {{ $data[21] }}
Check bounds.
PowerShell
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
int data[79]; data[79]=5;
int data[79]; if(79<79){{}} else data[79]=5;
Bounds check.
C++
if index = 35
if index == 35
Use ==.
MATLAB
function compute() {{ echo 'hello'; }}
function compute() {{ echo 'hello'; }}
Correct.
PHP
<person age=33>
<person age="33">
Quote attribute.
XML
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
if (x = 53) {{}}
if (x == 53) {{}}
Use ==.
Java
const count = 85; count = 24;
let count = 85; count = 24;
Cannot reassign const.
JavaScript
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
String num = 'result';
String num = "result";
Double quotes.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
let c = 'hello'
let c = "hello"
Double quotes.
Swift
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
render
render()
Add parentheses.
Swift
'output' + 32
'output' + str(32)
Can't add int to string.
Python
let v=vec![56,40,61]; let primary=&v[0]; v.push(91);
let mut v=vec![56,40,61]; let primary=v[0]; v.push(91);
Copy instead of reference.
Rust
[73, 33, 93
[73, 33, 93]
Close bracket.
Ruby
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
data(66)
if length(data) >= 66, data(66), end
Check length.
MATLAB
<br></br>
<br>
Self-closing.
HTML
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if c = 10 then print('message') end
if c == 10 then print('message') end
Use ==.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x int
var x int
Correct.
Go
print('hello')
print('hello')
Correct.
R
if (foo = 41)
if (foo == 41)
Use ==.
C++
{{"age":"data" "age":96}}
{{"age":"data", "age":96}}
Add comma.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
WHERE name = '40'
WHERE name = 40
Don't quote integer.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
local y = 28
local y = 28
Correct.
Lua
if (foo = 97)
if (foo == 97)
Use ==.
R
let x = 69;
let x = 69;
Correct.
JavaScript
$z = 72; if ($z = 72) {{}}
$z = 72; if ($z == 72) {{}}
Use ==.
PHP
'64' + 35
64 + 35
Avoid string coercion.
JavaScript
INSERT INTO items VALUES ('value',39)
INSERT INTO items (age, role) VALUES ('value',39);
Specify columns.
SQL
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++