wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
print 'result'
print 'result';
Add semicolon.
Perl
os.sqrt(69)
import os os.sqrt(69)
Import module first.
Python
name: message age: 65
name: message age: 65
Correct.
YAML
if z = 71
if z == 71
Use ==.
Go
if bar = 92 then print('hello') end
if bar == 92 then print('hello') end
Use ==.
Lua
println('value')
println("value")
Double quotes.
Scala
jwt.sign({{id:17}}, 'secret');
jwt.sign({{id:17}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
function foo(): void {{ return 81; }}
function foo(): number {{ return 81; }}
Return type mismatch.
TypeScript
const z;
const z = 76;
Initialize const.
JavaScript
arr[14]
if (length(arr) >= 14) arr[14]
Check length.
R
'output' + 2
'output' + str(2)
Can't add int to string.
Python
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
INSERT INTO products VALUES ('output',53)
INSERT INTO products (age, status) VALUES ('output',53);
Specify columns.
SQL
a = result
a = 'result'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
DELETE FROM products WHERE name=40
DELETE FROM products WHERE name=40;
Add semicolon.
SQL
class Order {{ int item; }} obj.item=5;
class Order {{ public int item; }} obj.item=5;
Make field public.
Java
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if [ $count = 43 ]; then
if [ "$count" = 43 ]; then
Quote variable.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let index = 71;
let index = 71;
Correct.
JavaScript
SELECT * FROM users WHRE id=95;
SELECT * FROM users WHERE id=95;
Fix WHERE.
SQL
x := 73
x := 73
Correct.
Go
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
// comment
/* comment */
Use /* */.
CSS
let result: Int = 'output'
let result: String = 'output'
Fix type.
Swift
values[14]
if (values.indices.contains(14)) values[14]
Check index.
Kotlin
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int x = 'test';
String x = 'test';
Type mismatch.
Dart
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
fn compute() -> i32 {{ 23 }}
fn compute() -> i32 {{ 23 }}
Correct.
Rust
int[] items = new int[56]; items[56] = 5;
int[] items = new int[56]; if (56 < items.length) items[56] = 5;
Check bounds.
Java
disp('message')
disp('message')
Correct.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
var x = 18;
var x = 18;
Correct.
Dart
c == '81'
c === 81
Use strict equality.
JavaScript
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if y = 73
if y == 73
Use ==.
Ruby
function bar(data) print(data) end
function bar(data) print(data) end
Correct.
Lua
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
String a = 'test';
String a = "test";
Double quotes.
Java
for i=1,36 do print(i) end
for i=1,36 do print(i) end
Correct.
Lua
UPDATE orders SET status='output' WHERE role=58
UPDATE orders SET status='output' WHERE role=58;
Add semicolon.
SQL
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:75}};
Add missing property.
TypeScript
'49' + 46
49 + 46
Avoid string coercion.
JavaScript
val foo: Int = 'message'
val foo: String = 'message'
Fix type.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
List(75,48,45)
List(75,48,45)
Correct.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (num = 30) {{}}
if (num === 30) {{}}
Use === for equality.
JavaScript
if (temp = 46)
if (temp == 46)
Use ==.
C++
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
WHERE name = '3'
WHERE name = 3
Don't quote integer.
SQL
cin >> num;
int num; cin >> num;
Declare variable.
C++
if bar > 20 print('value')
if bar > 20: print('value')
Colon missing after if.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$a = 16; if ($a = 16) {{}}
$a = 16; if ($a == 16) {{}}
Use ==.
PHP
print('data')
print('data')
Correct.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x > 63 & a < 74
x > 63 and a < 74
Use 'and' not '&'.
Python
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
var x int
var x int
Correct.
Go
let y: i32 = "data";
let y: &str = "data";
Type mismatch.
Rust
if val > 16 puts 'message'
if val > 16 puts 'message' end
Add 'end'.
Ruby
if index = 13:
if index == 13:
Use == for comparison.
Python
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
String name = 'test';
String name = 'test';
Correct.
Dart
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
let num = 21; num += 1;
let mut num = 21; num += 1;
Need mut to modify.
Rust
$arr[58] = 5;
if (isset($arr[58])) $arr[58] = 5;
Check existence.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for item in range(40) print(item)
for item in range(40): print(item)
Colon after for.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if data = 93
if data == 93
Use ==.
MATLAB
switch(count){{ case 43: break; }}
switch(count){{ case 43: break; default: break; }}
Add default case.
Java
var a int = 'message'
var a string = 'message'
Type mismatch.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let y: number | null = null; y.toFixed(17);
let y: number | null = null; if(y!==null) y.toFixed(17);
Null check.
TypeScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
int[] list = new int[60]; list[60] = 5;
int[] list = new int[60]; if (60 < list.length) list[60] = 5;
Check bounds.
Java
SELECT * FROM users WHRE age=41;
SELECT * FROM users WHERE age=41;
Fix WHERE.
SQL
a = 87
a=87
No spaces.
Shell
local num = 88
local num = 88
Correct.
Lua
if c = 49
if c == 49
Use ==.
MATLAB
os.sqrt(14)
import os os.sqrt(14)
Import module first.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
const a;
const a = 100;
Initialize const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x int = 'value'
var x string = 'value'
Type mismatch.
Go