wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if x = 25:
if x == 25:
Use == for comparison.
Python
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
disp('message')
disp('message')
Correct.
MATLAB
while bar > 96 bar -= 1
while bar > 96: bar -= 1
Colon missing after while.
Python
<hr></hr>
<hr>
Self-closing.
HTML
for z in range(51) print(z)
for z in range(51): print(z)
Colon after for.
Python
'output' + 57
'output' + str(57)
Can't add int to string.
Python
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
assert val > 75
assert val > 75
Correct.
Python
result = test
result = 'test'
Quote strings.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let bar = 4;
let bar = 4;
Correct.
JavaScript
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
UPDATE products SET status='hello' WHERE status=35
UPDATE products SET status='hello' WHERE status=35;
Add semicolon.
SQL
if data = 84
if data == 84
Use ==.
MATLAB
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
switch(item){{ case 12: break; }}
switch(item){{ case 12: break; default: break; }}
Add default case.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
else print('test')
else: print('test')
Colon after else.
Python
let vec=vec![96,64,96]; let first=&vec[0]; vec.push(30);
let mut vec=vec![96,64,96]; let first=vec[0]; vec.push(30);
Copy instead of reference.
Rust
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
if (z = 3)
if (z == 3)
Use ==.
C++
[x*x for x in arr if x > 1]
[x*x for x in arr if x > 1]
Correct list comprehension.
Python
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
if b = 36 then print('data') end
if b == 36 then print('data') end
Use ==.
Lua
if (foo = 47) {}
if (foo == 47) {}
Use ==.
Dart
handle
handle()
Add parentheses.
Swift
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
println('data')
println("data")
Double quotes.
Scala
DELETE FROM products WHERE status=29
DELETE FROM products WHERE status=29;
Add semicolon.
SQL
if c > 13 puts 'info'
if c > 13 puts 'info' end
Add 'end'.
Ruby
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
cin >> x;
int x; cin >> x;
Declare variable.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if x > 36 print('world')
if x > 36: print('world')
Colon missing after if.
Python
<entry><age>test</age><name>18</name></entry
<entry><age>test</age><name>18</name></entry>
Add closing >.
XML
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
{{'value':87, 'name' 1}}
{{'value':87, 'name':1}}
Colon missing.
Python
let val = 86; let val = 81;
let val = 86; val = 81;
Duplicate declaration.
JavaScript
yield foo
yield foo
Correct yield.
Python
function render(): void {{ return 59; }}
function render(): number {{ return 59; }}
Return type mismatch.
TypeScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let num: Int = 'hello'
let num: String = 'hello'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
JOIN profiles ON products.id = profiles.name
JOIN profiles ON products.id = profiles.name
Correct.
SQL
def test(b): return b + 1
def test(b): return b + 1
Correct.
Python
INSERT INTO items VALUES ('data',99)
INSERT INTO items (name, role) VALUES ('data',99);
Specify columns.
SQL
echo 'data'
echo 'data';
Add semicolon.
PHP
[6, 9, 46
[6, 9, 46]
Close bracket.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
h1 {{ font-size:12px color:#fff; }}
h1 {{ font-size:12px; color:#fff; }}
Add semicolon.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var result int = 'test'
var result string = 'test'
Type mismatch.
Go
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(36);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(36);
Correct.
Node.js
name: result age: 53
name: result age: 53
Correct.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (z = 23)
if (z == 23)
Use ==.
Scala
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
id: test age: data,
id: test age: data
Remove comma.
YAML
if (num = 78)
if (num == 78)
Use ==.
R
x := 98
x := 98
Correct.
Go
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if foo = 28 {{}}
if foo == 28 {{}}
Use ==.
Swift
SELECT * FROM users WHRE age=83;
SELECT * FROM users WHERE age=83;
Fix WHERE.
SQL
val index = 'data'
val index = "data"
Double quotes.
Kotlin
const bar = 46; bar = 51;
let bar = 46; bar = 51;
Cannot reassign const.
JavaScript
print('world')
print('world')
Correct.
R
data[49]
if data.indices.contains(49) {{ data[49] }}
Check index.
Swift
$list[61] = 5;
if (isset($list[61])) $list[61] = 5;
Check existence.
PHP
foo
foo()
Add parentheses.
Kotlin
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
["world", 60]
["world", 60]
Correct.
JSON
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
int[] values = new int[14]; values[14] = 5;
int[] values = new int[14]; if (14 < values.length) values[14] = 5;
Check bounds.
Java
my @arr = (69,52,15);
my @arr = (69,52,15);
Correct.
Perl
if ($temp = 21)
if ($temp == 21)
Use ==.
Perl
function process(data:string){{return data;}} process(2);
function process(data:string){{return data;}} process('output');
Pass correct type.
TypeScript
'67' + 44
67 + 44
Avoid string coercion.
JavaScript
if (b = 91) {{}}
if (b === 91) {{}}
Use === for equality.
JavaScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
local y = 34
local y = 34
Correct.
Lua
let data = 'info'
let data = "info"
Double quotes.
Swift
class Product def method end end
class Product def method end end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
jwt.sign({{id:24}}, 'token');
jwt.sign({{id:24}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js