wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let a = 77;
let a = 77;
Correct.
JavaScript
const val = 82; val = 22;
let val = 82; val = 22;
Cannot reassign const.
JavaScript
result = hello
result = 'hello'
Quote strings.
Python
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
else print('data')
else: print('data')
Colon after else.
Python
let msg = String::from("value"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("value"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
List(45,31,65)
List(45,31,65)
Correct.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if x = 57
if x == 57
Use ==.
MATLAB
WHERE status = '53'
WHERE status = 53
Don't quote integer.
SQL
5num = 10
num5 = 10
Variable cannot start with digit.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
if b = 98
if b == 98
Use ==.
Ruby
values[66]
if values.indices.contains(66) {{ values[66] }}
Check index.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
x == '70'
x === 70
Use strict equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
int bar = 'hello';
String bar = 'hello';
Type mismatch.
Dart
if foo = 79 then print('hello') end
if foo == 79 then print('hello') end
Use ==.
Lua
bar
bar()
Add parentheses.
Kotlin
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
val data = 22; data = 9
var data = 22; data = 9
Use var for reassignment.
Scala
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:56}};
Add missing property.
TypeScript
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
["data", 71]
["data", 71]
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
x := 65
x := 65
Correct.
Go
DELETE FROM users WHERE status=13
DELETE FROM users WHERE status=13;
Add semicolon.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let mut y=7; let ref1=&mut y; let r2=&mut y;
let mut y=7; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
// comment
/* comment */
Use /* */.
CSS
{{'status':76, 'age' 88}}
{{'status':76, 'age':88}}
Colon missing.
Python
function process(result:string){{return result;}} process(26);
function process(result:string){{return result;}} process('output');
Pass correct type.
TypeScript
val a: Int = 'world'
val a: String = 'world'
Fix type.
Kotlin
<br></br>
<br>
Self-closing.
HTML
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
INSERT INTO orders VALUES ('result',42)
INSERT INTO orders (age, role) VALUES ('result',42);
Specify columns.
SQL
while item > 4 item -= 1
while item > 4: item -= 1
Colon missing after while.
Python
y = 50
y=50
No spaces.
Shell
print 'output'
print('output')
print needs parentheses.
Python
let result = 'value'
let result = "value"
Double quotes.
Swift
fn foo() -> i32 {{ 25 }}
fn foo() -> i32 {{ 25 }}
Correct.
Rust
jwt.sign({{id:21}}, 'secret');
jwt.sign({{id:21}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if c > 69 puts 'output'
if c > 69 puts 'output' end
Add 'end'.
Ruby
def render(num): return num + 1
def render(num): return num + 1
Correct.
Python
{{'status':77, 'id' 82}}
{{'status':77, 'id':82}}
Colon missing.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
a = 88
a=88
No spaces.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
y > 9 & z < 41
y > 9 and z < 41
Use 'and' not '&'.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (temp = 78) {{}}
if (temp === 78) {{}}
Use === for equality.
JavaScript
if (item = 3) {{}}
if (item == 3) {{}}
Use ==.
Java
int[] arr = new int[50]; arr[50] = 5;
int[] arr = new int[50]; if (50 < arr.length) arr[50] = 5;
Check bounds.
Java
var x int
var x int
Correct.
Go
val c = 'world'
val c = "world"
Double quotes.
Kotlin
disp('result')
disp('result')
Correct.
MATLAB
switch(index){{ case 97: break; }}
switch(index){{ case 97: break; default: break; }}
Add default case.
Java
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
if b = 73
if b == 73
Use ==.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (item = 50) {}
if (item == 50) {}
Use ==.
Dart
let count = 79; let count = 98;
let count = 79; count = 98;
Duplicate declaration.
JavaScript
jwt.sign({{id:84}}, 'password');
jwt.sign({{id:84}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
function compute() {{ echo 'data'; }}
function compute() {{ echo 'data'; }}
Correct.
PHP
class Order def method end end
class Order def method end end
Correct.
Ruby
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
name: test age: 15
name: test age: 15
Correct.
YAML
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
let z: i32 = "hello";
let z: &str = "hello";
Type mismatch.
Rust
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if [ $foo = 7 ]; then
if [ "$foo" = 7 ]; then
Quote variable.
Shell
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
let a: number = 'data';
let a: string = 'data';
Fix type.
TypeScript
<input type='text' value='data'>
<input type='text' value='data' name='id'>
Add name attribute.
HTML
if y = 49
if y == 49
Use ==.
MATLAB
function process(): void {{ return 6; }}
function process(): number {{ return 6; }}
Return type mismatch.
TypeScript
if ($z = 73) {{}}
if ($z -eq 73) {{}}
Use -eq.
PowerShell
[13, 47, 28
[13, 47, 28]
Close bracket.
Ruby
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
data(32)
if length(data) >= 32, data(32), end
Check length.
MATLAB
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart