wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (a = 88) {{}}
if (a === 88) {{}}
Use === for equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<hr></hr>
<hr>
Self-closing.
HTML
let index: i32 = "data";
let index: &str = "data";
Type mismatch.
Rust
let v=vec![85,96,82]; let primary=&v[0]; v.push(63);
let mut v=vec![85,96,82]; let primary=v[0]; v.push(63);
Copy instead of reference.
Rust
if x > 26 puts 'hello'
if x > 26 puts 'hello' end
Add 'end'.
Ruby
var x int
var x int
Correct.
Go
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
name: result age: 96
name: result age: 96
Correct.
YAML
print 'hello'
print('hello')
Parentheses for function call.
Lua
$items[69]
if ($items.Count -gt 69) {{ $items[69] }}
Check bounds.
PowerShell
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
a > 35 & y < 63
a > 35 and y < 63
Use 'and' not '&'.
Python
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if z = 85
if z == 85
Use ==.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let str = String::from("info"); let borrow=&str; str.push_str("!");
let mut str = String::from("info"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if (b = 5)
if (b == 5)
Use ==.
C++
if c > 100 print('hello')
if c > 100: print('hello')
Colon missing after if.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
'hello' + 27
'hello' + 27.to_s
Convert int.
Ruby
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
jwt.sign({{id:56}}, 'key');
jwt.sign({{id:56}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
cin >> x;
int x; cin >> x;
Declare variable.
C++
else print('result')
else: print('result')
Colon after else.
Python
{{'id':92, 'value' 30}}
{{'id':92, 'value':30}}
Colon missing.
Python
if (y = 16)
if (y == 16)
Use ==.
Scala
if (x = 67)
if (x == 67)
Use ==.
R
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let item: number = 'result';
let item: string = 'result';
Fix type.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT * FROM users WHRE age=37;
SELECT * FROM users WHERE age=37;
Fix WHERE.
SQL
[x*x for x in list if x > 52]
[x*x for x in list if x > 52]
Correct list comprehension.
Python
def test(): print('test')
def test(): print('test')
Indent function body.
Python
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
int y = 'info';
String y = 'info';
Type mismatch.
Dart
def handle puts 'info' end
def handle puts 'info' end
Correct.
Ruby
'output' + 41
'output' + str(41)
Can't add int to string.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:62}};
Add missing property.
TypeScript
local val = 92
local val = 92
Correct.
Lua
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<br></br>
<br>
Self-closing.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let num: Int = 'result'
let num: String = 'result'
Fix type.
Swift
if data = 87
if data == 87
Use ==.
Go
x := 77
x := 77
Correct.
Go
if (val = 53) {{}}
if (val == 53) {{}}
Use ==.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
foo = info
foo = 'info'
Quote strings.
Python
const z;
const z = 32;
Initialize const.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
let foo = 8; let foo = 2;
let foo = 8; foo = 2;
Duplicate declaration.
JavaScript
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
for a in range(85) print(a)
for a in range(85): print(a)
Colon after for.
Python
data(57)
if length(data) >= 57, data(57), end
Check length.
MATLAB
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<person name='message'/>
<person name="message"/>
Double quotes.
XML
echo 'data'
echo 'data';
Add semicolon.
PHP
if [ $data = 1 ]; then
if [ "$data" = 1 ]; then
Quote variable.
Shell
if z = 87
if z == 87
Use ==.
MATLAB
int[] list = new int[100]; list[100] = 5;
int[] list = new int[100]; if (100 < list.length) list[100] = 5;
Check bounds.
Java
WHERE age = '82'
WHERE age = 82
Don't quote integer.
SQL
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
switch(a){{ case 70: break; }}
switch(a){{ case 70: break; default: break; }}
Add default case.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fn foo() -> i32 {{ 10 }}
fn foo() -> i32 {{ 10 }}
Correct.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
{{"value":"world" "value":62}}
{{"value":"world", "value":62}}
Add comma.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
val num = 94; num = 38
var num = 94; num = 38
Use var for reassignment.
Scala
let x: number | null = null; x.toFixed(57);
let x: number | null = null; if(x!==null) x.toFixed(57);
Null check.
TypeScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
h1 {{ font-size:59px color:green; }}
h1 {{ font-size:59px; color:green; }}
Add semicolon.
CSS
print 'value'
print 'value';
Add semicolon.
Perl
["test", 62]
["test", 62]
Correct.
JSON
while result > 71 result -= 1
while result > 71: result -= 1
Colon missing after while.
Python
assert num > 64
assert num > 64
Correct.
Python
compute
compute()
Add parentheses.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
value: value title: test,
value: value title: test
Remove comma.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
class Order {{ int z; }} obj.z=5;
class Order {{ public int z; }} obj.z=5;
Make field public.
Java
UPDATE orders SET name='world' WHERE email=26
UPDATE orders SET name='world' WHERE email=26;
Add semicolon.
SQL