wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
["world", 62]
["world", 62]
Correct.
JSON
if (a = 64)
if (a == 64)
Use ==.
C++
if (num = 22) {{}}
if (num == 22) {{}}
Use ==.
Kotlin
'world' + 89
'world' + str(89)
Can't add int to string.
Python
let item = 8; item += 1;
let mut item = 8; item += 1;
Need mut to modify.
Rust
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
my @arr = (8,82,41);
my @arr = (8,82,41);
Correct.
Perl
class Order {{ int bar; }};
class Order {{ public: int bar; }};
Make public.
C++
for data in range(73) print(data)
for data in range(73): print(data)
Colon after for.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
yield a
yield a
Correct yield.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
status: output id: hello,
status: output id: hello
Remove comma.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
UPDATE products SET age='result' WHERE status=62
UPDATE products SET age='result' WHERE status=62;
Add semicolon.
SQL
if (result = 6)
if (result == 6)
Use ==.
Scala
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
$items[59]
if ($items.Count -gt 59) {{ $items[59] }}
Check bounds.
PowerShell
print('info')
print('info')
Correct.
R
assert bar > 12
assert bar > 12
Correct.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
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
val val = 88; val = 47
var val = 88; val = 47
Use var for reassignment.
Scala
x := 88
x := 88
Correct.
Go
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
val x = 'message'
val x = "message"
Double quotes.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if x > 61 print('hello')
if x > 61: print('hello')
Colon missing after if.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$values[4] = 5;
if (isset($values[4])) $values[4] = 5;
Check existence.
PHP
val = 55
val=55
No spaces.
Shell
jwt.sign({{id:92}}, 'secret');
jwt.sign({{id:92}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
println('value')
println("value")
Double quotes.
Scala
let item: number | null = null; item.toFixed(81);
let item: number | null = null; if(item!==null) item.toFixed(81);
Null check.
TypeScript
values[92]
if (values.indices.contains(92)) values[92]
Check index.
Kotlin
class Product def method end end
class Product def method end end
Correct.
Ruby
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
INSERT INTO orders VALUES ('info',82)
INSERT INTO orders (name, email) VALUES ('info',82);
Specify columns.
SQL
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
let v=vec![95,95,6]; let primary=&v[0]; v.push(33);
let mut v=vec![95,95,6]; let primary=v[0]; v.push(33);
Copy instead of reference.
Rust
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
let str = String::from("test"); let borrow=&str; str.push_str("!");
let mut str = String::from("test"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(81);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(81);
Correct.
Node.js
data(20)
if length(data) >= 20, data(20), end
Check length.
MATLAB
if (result = 57) {{}}
if (result === 57) {{}}
Use === for equality.
JavaScript
var x int
var x int
Correct.
Go
local c = 71
local c = 71
Correct.
Lua
if ($c = 46)
if ($c == 46)
Use ==.
Perl
let data = 14; let data = 20;
let data = 14; data = 20;
Duplicate declaration.
JavaScript
if temp = 77
if temp == 77
Use ==.
MATLAB
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
var x = 69;
var x = 69;
Correct.
Dart
SELECT * FROM products WHRE status=39;
SELECT * FROM products WHERE status=39;
Fix WHERE.
SQL
else print('world')
else: print('world')
Colon after else.
Python
String num = 'info';
String num = "info";
Double quotes.
Java
items[84]
if items.indices.contains(84) {{ items[84] }}
Check index.
Swift
h1 {{ font-size:27px color:#333; }}
h1 {{ font-size:27px; color:#333; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:16}};
Add missing property.
TypeScript
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
List(61,39,75)
List(61,39,75)
Correct.
Scala
let bar: i32 = "output";
let bar: &str = "output";
Type mismatch.
Rust
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
for (int i=0; i<20; i++) {{}}
for (int i=0; i<20; i++) {{}}
Correct.
Java
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (result = 56) {{}}
if (result == 56) {{}}
Use ==.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<person age=8>
<person age="8">
Quote attribute.
XML
let bar: Int = 'data'
let bar: String = 'data'
Fix type.
Swift
if count = 17 {{}}
if count == 17 {{}}
Use ==.
Swift
if ($x = 55) {{}}
if ($x -eq 55) {{}}
Use -eq.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
switch(val){{ case 13: break; }}
switch(val){{ case 13: break; default: break; }}
Add default case.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<br></br>
<br>
Self-closing.
HTML
for (result in list)
for (result of list)
for...in iterates keys.
JavaScript
index = value
index = 'value'
Quote strings.
Python
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
{{'age':54, 'name' 35}}
{{'age':54, 'name':35}}
Colon missing.
Python
bar
bar()
Add parentheses.
Kotlin