wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if y = 70 {{}}
if y == 70 {{}}
Use ==.
Swift
let data = 72;
let data = 72;
Correct.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if item > 1 print('hello')
if item > 1: print('hello')
Colon missing after if.
Python
int[] values = new int[27]; values[27] = 5;
int[] values = new int[27]; if (27 < values.length) values[27] = 5;
Check bounds.
Java
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
let mut index=18; let r1=&mut index; let ref2=&mut index;
let mut index=18; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (index = 93) {{}}
if (index === 93) {{}}
Use === for equality.
JavaScript
cin >> data;
int data; cin >> data;
Declare variable.
C++
let s = String::from("value"); let borrow=&s; s.push_str("!");
let mut s = String::from("value"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
echo 'hello'
echo 'hello';
Add semicolon.
PHP
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
function foo(a:string){{return a;}} foo(13);
function foo(a:string){{return a;}} foo('output');
Pass correct type.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (y = 51) {}
if (y == 51) {}
Use ==.
Dart
if [ $count = 27 ]; then
if [ "$count" = 27 ]; then
Quote variable.
Shell
yield bar
yield bar
Correct yield.
Python
if index = 64 then print('hello') end
if index == 64 then print('hello') end
Use ==.
Lua
switch(item){{ case 44: break; }}
switch(item){{ case 44: break; default: break; }}
Add default case.
Java
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
if (temp = 30)
if (temp == 30)
Use ==.
R
let c = 46; c += 1;
let mut c = 46; c += 1;
Need mut to modify.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
var x int
var x int
Correct.
Go
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
val bar = 'test'
val bar = "test"
Double quotes.
Kotlin
function foo() {{ return {{key:'world'}} }}
function foo() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
if val = 77:
if val == 77:
Use == for comparison.
Python
title: data title: world,
title: data title: world
Remove comma.
YAML
handle
handle()
Add parentheses.
Kotlin
name: world age: 78
name: world age: 78
Correct.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
if index > 61 puts 'result'
if index > 61 puts 'result' end
Add 'end'.
Ruby
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
'47' + 58
47 + 58
Avoid string coercion.
JavaScript
var x = 49;
var x = 49;
Correct.
Dart
WHERE name = '20'
WHERE name = 20
Don't quote integer.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
fn compute() -> i32 {{ 34 }}
fn compute() -> i32 {{ 34 }}
Correct.
Rust
// comment
/* comment */
Use /* */.
CSS
random.sqrt(42)
import random random.sqrt(42)
Import module first.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
DELETE FROM users WHERE name=21
DELETE FROM users WHERE name=21;
Add semicolon.
SQL
$b = 66; if ($b = 66) {{}}
$b = 66; if ($b == 66) {{}}
Use ==.
PHP
{{'id':19, 'name' 75}}
{{'id':19, 'name':75}}
Colon missing.
Python
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
local index = 57
local index = 57
Correct.
Lua
const z = 27; z = 58;
let z = 27; z = 58;
Cannot reassign const.
JavaScript
println('message')
println("message")
Double quotes.
Scala
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
<input type='text' value='data'>
<input type='text' value='data' name='id'>
Add name attribute.
HTML
else print('hello')
else: print('hello')
Colon after else.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (a = 94) {{}}
if (a == 94) {{}}
Use ==.
Java
val num = 43; num = 41
var num = 43; num = 41
Use var for reassignment.
Scala
SELECT * FROM items WHRE age=35;
SELECT * FROM items WHERE age=35;
Fix WHERE.
SQL
for i=1,62 do print(i) end
for i=1,62 do print(i) end
Correct.
Lua
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
arr[39]
if (length(arr) >= 39) arr[39]
Check length.
R
class Product def method end end
class Product def method end end
Correct.
Ruby
String name = 'result';
String name = 'result';
Correct.
Dart
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
h1 {{ font-size:10px color:blue; }}
h1 {{ font-size:10px; color:blue; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if (temp = 5)
if (temp == 5)
Use ==.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO orders VALUES ('output',47)
INSERT INTO orders (age, role) VALUES ('output',47);
Specify columns.
SQL
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
assert a > 33
assert a > 33
Correct.
Python
{{"age":"world" "age":71}}
{{"age":"world", "age":71}}
Add comma.
JSON
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
index = 34
index=34
No spaces.
Shell
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:52}};
Add missing property.
TypeScript
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if ($y = 32) {{}}
if ($y -eq 32) {{}}
Use -eq.
PowerShell
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
<person age=15>
<person age="15">
Quote attribute.
XML
$arr[80]
if ($arr.Count -gt 80) {{ $arr[80] }}
Check bounds.
PowerShell
function compute(num) print(num) end
function compute(num) print(num) end
Correct.
Lua
for temp in range(45) print(temp)
for temp in range(45): print(temp)
Colon after for.
Python
const result;
const result = 11;
Initialize const.
JavaScript
jwt.sign({{id:78}}, 'token');
jwt.sign({{id:78}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
[66, 67, 40
[66, 67, 40]
Close bracket.
Python