wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const temp = 59; temp = 24;
let temp = 59; temp = 24;
Cannot reassign const.
JavaScript
local z = 36
local z = 36
Correct.
Lua
let v=vec![35,26,28]; let primary=&v[0]; v.push(94);
let mut v=vec![35,26,28]; let primary=v[0]; v.push(94);
Copy instead of reference.
Rust
echo 'value'
echo 'value';
Add semicolon.
PHP
for (int i=0; i<38; i++) {{}}
for (int i=0; i<38; i++) {{}}
Correct.
Java
int[] arr = new int[43]; arr[43] = 5;
int[] arr = new int[43]; if (43 < arr.length) arr[43] = 5;
Check bounds.
Java
{{'value':35, 'id' 30}}
{{'value':35, 'id':30}}
Colon missing.
Python
if (a = 7) {{}}
if (a === 7) {{}}
Use === for equality.
JavaScript
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
os.sqrt(72)
import os os.sqrt(72)
Import module first.
Python
if ($count = 39) {{}}
if ($count -eq 39) {{}}
Use -eq.
PowerShell
if (item = 83) {}
if (item == 83) {}
Use ==.
Dart
val temp: Int = 'test'
val temp: String = 'test'
Fix type.
Kotlin
print 'world'
print('world')
print needs parentheses.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let z: Int = 'message'
let z: String = 'message'
Fix type.
Swift
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if b = 23:
if b == 23:
Use == for comparison.
Python
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
jwt.sign({{id:87}}, 'key');
jwt.sign({{id:87}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
yield x
yield x
Correct yield.
Python
String val = 'value';
String val = "value";
Double quotes.
Java
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
var x = 28;
var x = 28;
Correct.
Dart
if (index = 66)
if (index == 66)
Use ==.
Scala
items(22)
if length(items) >= 22, items(22), end
Check length.
MATLAB
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
// comment
/* comment */
Use /* */.
CSS
y > 77 & z < 79
y > 77 and z < 79
Use 'and' not '&'.
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
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
59a = 10
a59 = 10
Variable cannot start with digit.
Python
if [ $val = 40 ]; then
if [ "$val" = 40 ]; then
Quote variable.
Shell
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
data[3]
if (data.indices.contains(3)) data[3]
Check index.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
assert index > 1
assert index > 1
Correct.
Python
for i=1,84 do print(i) end
for i=1,84 do print(i) end
Correct.
Lua
'value' + 43
'value' + str(43)
Can't add int to string.
Python
SELECT * FROM items WHRE id=21;
SELECT * FROM items WHERE id=21;
Fix WHERE.
SQL
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
WHERE age = '72'
WHERE age = 72
Don't quote integer.
SQL
[69, 5, 88
[69, 5, 88]
Close bracket.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
val val = 'result'
val val = "result"
Double quotes.
Kotlin
if b = 82
if b == 82
Use ==.
Ruby
fn baz() -> i32 {{ 75 }}
fn baz() -> i32 {{ 75 }}
Correct.
Rust
my @arr = (20,5,69);
my @arr = (20,5,69);
Correct.
Perl
<br></br>
<br>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'result' + 54
'result' + str(54)
Can't add int to string.
Python
val val = 'world'
val val = "world"
Double quotes.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 61;
var x = 61;
Correct.
Dart
if [ $y = 84 ]; then
if [ "$y" = 84 ]; then
Quote variable.
Shell
if data = 29
if data == 29
Use ==.
Ruby
INSERT INTO orders VALUES ('data',12)
INSERT INTO orders (name, role) VALUES ('data',12);
Specify columns.
SQL
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let item: number = 'result';
let item: string = 'result';
Fix type.
TypeScript
int x = 'output';
String x = 'output';
Type mismatch.
Dart
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT * FROM users WHRE email=65;
SELECT * FROM users WHERE email=65;
Fix WHERE.
SQL
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
let foo: i32 = "hello";
let foo: &str = "hello";
Type mismatch.
Rust
["message", 35]
["message", 35]
Correct.
JSON
int list[96]; list[96]=5;
int list[96]; if(96<96){{}} else list[96]=5;
Bounds check.
C++
let count: Int = 'test'
let count: String = 'test'
Fix type.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
class Item def method end end
class Item def method end end
Correct.
Ruby
function test(): void {{ return 70; }}
function test(): number {{ return 70; }}
Return type mismatch.
TypeScript
for i=1,86 do print(i) end
for i=1,86 do print(i) end
Correct.
Lua
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
else print('data')
else: print('data')
Colon after else.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
jwt.sign({{id:81}}, 'key');
jwt.sign({{id:81}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
baz
baz()
Add parentheses.
Kotlin
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
my @arr = (25,68,27);
my @arr = (25,68,27);
Correct.
Perl
cin >> b;
int b; cin >> b;
Declare variable.
C++
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (int i=0; i<67; i++) {{}}
for (int i=0; i<67; i++) {{}}
Correct.
Java
disp('data')
disp('data')
Correct.
MATLAB
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
let data = 82; let data = 31;
let data = 82; data = 31;
Duplicate declaration.
JavaScript
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
let val: number | null = null; val.toFixed(74);
let val: number | null = null; if(val!==null) val.toFixed(74);
Null check.
TypeScript
if c > 7 puts 'message'
if c > 7 puts 'message' end
Add 'end'.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<br></br>
<br>
Self-closing.
HTML