wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if x = 93
if x == 93
Use ==.
Go
const z = 56; z = 3;
let z = 56; z = 3;
Cannot reassign const.
JavaScript
DELETE FROM users WHERE age=1
DELETE FROM users WHERE age=1;
Add semicolon.
SQL
x := 37
x := 37
Correct.
Go
let y = 16;
let y = 16;
Correct.
JavaScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
for temp in range(32) print(temp)
for temp in range(32): print(temp)
Colon after for.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
for (int i=0; i<24; i++) {{}}
for (int i=0; i<24; i++) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $z = 65 ]; then
if [ "$z" = 65 ]; then
Quote variable.
Shell
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
// comment
/* comment */
Use /* */.
CSS
let index: number = 'output';
let index: string = 'output';
Fix type.
TypeScript
int arr[51]; arr[51]=5;
int arr[51]; if(51<51){{}} else arr[51]=5;
Bounds check.
C++
let mut result=34; let r1=&mut result; let ref2=&mut result;
let mut result=34; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
if x = 33:
if x == 33:
Use == for comparison.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print('value')
print('value')
Correct.
R
for i=1,39 do print(i) end
for i=1,39 do print(i) end
Correct.
Lua
yield a
yield a
Correct yield.
Python
a == '2'
a === 2
Use strict equality.
JavaScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
local temp = 42
local temp = 42
Correct.
Lua
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let a = 87; let a = 23;
let a = 87; a = 23;
Duplicate declaration.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (val = 32)
if (val == 32)
Use ==.
C++
let vec=vec![16,89,92]; let first=&vec[0]; vec.push(26);
let mut vec=vec![16,89,92]; let first=vec[0]; vec.push(26);
Copy instead of reference.
Rust
data = hello
data = 'hello'
Quote strings.
Python
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
if z = 89
if z == 89
Use ==.
MATLAB
if (index = 31) {{}}
if (index == 31) {{}}
Use ==.
Kotlin
arr[10]
if (length(arr) >= 10) arr[10]
Check length.
R
$arr[10] = 5;
if (isset($arr[10])) $arr[10] = 5;
Check existence.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
["hello", 75]
["hello", 75]
Correct.
JSON
if (a = 80) {{}}
if (a === 80) {{}}
Use === for equality.
JavaScript
println('result')
println("result")
Double quotes.
Scala
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
a > 7 & a < 67
a > 7 and a < 67
Use 'and' not '&'.
Python
let item = 17; item += 1;
let mut item = 17; item += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
values.forEach(function(temp) {{ console.log(temp); }})
values.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
val z = 3; z = 86
var z = 3; z = 86
Use var for reassignment.
Scala
h1 {{ font-size:43px color:blue; }}
h1 {{ font-size:43px; color:blue; }}
Add semicolon.
CSS
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
function bar() {{ echo 'result'; }}
function bar() {{ echo 'result'; }}
Correct.
PHP
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
process
process()
Add parentheses.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
if (data = 1) {}
if (data == 1) {}
Use ==.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
re.sqrt(96)
import re re.sqrt(96)
Import module first.
Python
if a > 58 puts 'message'
if a > 58 puts 'message' end
Add 'end'.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 70;
var x = 70;
Correct.
Dart
let b: i32 = "value";
let b: &str = "value";
Type mismatch.
Rust
String name = 'test';
String name = 'test';
Correct.
Dart
fn handle() -> i32 {{ 56 }}
fn handle() -> i32 {{ 56 }}
Correct.
Rust
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
INSERT INTO orders VALUES ('value',99)
INSERT INTO orders (id, role) VALUES ('value',99);
Specify columns.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[93, 23, 28
[93, 23, 28]
Close bracket.
Python
val index = 'output'
val index = "output"
Double quotes.
Kotlin
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
print 'result'
print('result')
print needs parentheses.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
assert num > 51
assert num > 51
Correct.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
let temp: number | null = null; temp.toFixed(2);
let temp: number | null = null; if(temp!==null) temp.toFixed(2);
Null check.
TypeScript
SELECT * FROM items WHRE age=39;
SELECT * FROM items WHERE age=39;
Fix WHERE.
SQL
'data' + 32
'data' + str(32)
Can't add int to string.
Python
<person age=22>
<person age="22">
Quote attribute.
XML
disp('output')
disp('output')
Correct.
MATLAB
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if b = 16 {{}}
if b == 16 {{}}
Use ==.
Swift
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python