wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
function baz(): void {{ return 66; }}
function baz(): number {{ return 66; }}
Return type mismatch.
TypeScript
<person age=44>
<person age="44">
Quote attribute.
XML
if (count = 63) {{}}
if (count == 63) {{}}
Use ==.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
WHERE age = '77'
WHERE age = 77
Don't quote integer.
SQL
SELECT * FROM items WHRE age=50;
SELECT * FROM items WHERE age=50;
Fix WHERE.
SQL
let b = 31;
let b = 31;
Correct.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
val z = 61; z = 48
var z = 61; z = 48
Use var for reassignment.
Scala
let result = 'world'
let result = "world"
Double quotes.
Swift
jwt.sign({{id:25}}, 'token');
jwt.sign({{id:25}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
'20' + 46
20 + 46
Avoid string coercion.
JavaScript
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
sys.sqrt(23)
import sys sys.sqrt(23)
Import module first.
Python
{{"id":"result" "name":22}}
{{"id":"result", "name":22}}
Add comma.
JSON
INSERT INTO products VALUES ('world',23)
INSERT INTO products (age, role) VALUES ('world',23);
Specify columns.
SQL
if (z = 95) {{}}
if (z === 95) {{}}
Use === for equality.
JavaScript
for a in range(87) print(a)
for a in range(87): print(a)
Colon after for.
Python
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
arr[59]
if (length(arr) >= 59) arr[59]
Check length.
R
let result = 83; let result = 83;
let result = 83; result = 83;
Duplicate declaration.
JavaScript
let data: number = 'message';
let data: string = 'message';
Fix type.
TypeScript
const result;
const result = 71;
Initialize const.
JavaScript
if result = 89
if result == 89
Use ==.
Go
int[] items = new int[90]; items[90] = 5;
int[] items = new int[90]; if (90 < items.length) items[90] = 5;
Check bounds.
Java
let msg = String::from("data"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("data"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
[25, 24, 11
[25, 24, 11]
Close bracket.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if ($bar = 93) {{}}
if ($bar -eq 93) {{}}
Use -eq.
PowerShell
// comment
/* comment */
Use /* */.
CSS
int arr[28]; arr[28]=5;
int arr[28]; if(28<28){{}} else arr[28]=5;
Bounds check.
C++
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
yield result
yield result
Correct yield.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
function baz(count:string){{return count;}} baz(78);
function baz(count:string){{return count;}} baz('hello');
Pass correct type.
TypeScript
if (x = 11)
if (x == 11)
Use ==.
Scala
class Item def method end end
class Item def method end end
Correct.
Ruby
my @arr = (59,9,18);
my @arr = (59,9,18);
Correct.
Perl
if (data = 19)
if (data == 19)
Use ==.
R
function render(temp) print(temp) end
function render(temp) print(temp) end
Correct.
Lua
DELETE FROM products WHERE id=49
DELETE FROM products WHERE id=49;
Add semicolon.
SQL
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if [ $b = 44 ]; then
if [ "$b" = 44 ]; then
Quote variable.
Shell
if (count = 51) {}
if (count == 51) {}
Use ==.
Dart
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
for (int i=0; i<87; i++) {{}}
for (int i=0; i<87; i++) {{}}
Correct.
Java
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
print 'result'
print('result')
print needs parentheses.
Python
63count = 10
count63 = 10
Variable cannot start with digit.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let mut index=95; let r1=&mut index; let r2=&mut index;
let mut index=95; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
if ($num = 26)
if ($num == 26)
Use ==.
Perl
while item > 66 item -= 1
while item > 66: item -= 1
Colon missing after while.
Python
local a = 53
local a = 53
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if index = 8 then print('data') end
if index == 8 then print('data') end
Use ==.
Lua
val foo: Int = 'message'
val foo: String = 'message'
Fix type.
Kotlin
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
values[45]
if values.indices.contains(45) {{ values[45] }}
Check index.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
bar = 71
bar=71
No spaces.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
list[36]
if (list.indices.contains(36)) list[36]
Check index.
Kotlin
<person name='value'/>
<person name="value"/>
Double quotes.
XML
let x = 63; x += 1;
let mut x = 63; x += 1;
Need mut to modify.
Rust
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
x := 32
x := 32
Correct.
Go
else print('result')
else: print('result')
Colon after else.
Python
let result: Int = 'result'
let result: String = 'result'
Fix type.
Swift
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
[x*x for x in data if x > 73]
[x*x for x in data if x > 73]
Correct list comprehension.
Python
<br></br>
<br>
Self-closing.
HTML
echo 'value'
echo 'value';
Add semicolon.
PHP
if temp = 26:
if temp == 26:
Use == for comparison.
Python
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if bar = 34
if bar == 34
Use ==.
Go
age: test name: test,
age: test name: test
Remove comma.
YAML
if count = 4
if count == 4
Use ==.
MATLAB
h1 {{ font-size:33px color:red; }}
h1 {{ font-size:33px; color:red; }}
Add semicolon.
CSS
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
for i=1,96 do print(i) end
for i=1,96 do print(i) end
Correct.
Lua
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:3}};
Add missing property.
TypeScript