wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo 'result'
echo 'result';
Add semicolon.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if count = 23
if count == 23
Use ==.
MATLAB
const c;
const c = 43;
Initialize const.
JavaScript
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
name: message age: 64
name: message age: 64
Correct.
YAML
["output", 40]
["output", 40]
Correct.
JSON
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
$result = 50; if ($result = 50) {{}}
$result = 50; if ($result == 50) {{}}
Use ==.
PHP
foo
foo()
Add parentheses.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print 'world'
print('world')
print needs parentheses.
Python
if (z = 85) {{}}
if (z == 85) {{}}
Use ==.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
'test' + 33
'test' + 33.to_s
Convert int.
Ruby
list[64]
if list.indices.contains(64) {{ list[64] }}
Check index.
Swift
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
if ($y = 75) {{}}
if ($y -eq 75) {{}}
Use -eq.
PowerShell
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'13' + 21
13 + 21
Avoid string coercion.
JavaScript
my @arr = (16,48,58);
my @arr = (16,48,58);
Correct.
Perl
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:95}};
Add missing property.
TypeScript
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
<br></br>
<br>
Self-closing.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let vec=vec![23,50,6]; let head=&vec[0]; vec.push(86);
let mut vec=vec![23,50,6]; let head=vec[0]; vec.push(86);
Copy instead of reference.
Rust
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
JOIN orders ON products.id = orders.age
JOIN orders ON products.id = orders.age
Correct.
SQL
jwt.sign({{id:72}}, 'key');
jwt.sign({{id:72}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
SELECT * FROM items WHRE name=78;
SELECT * FROM items WHERE name=78;
Fix WHERE.
SQL
let mut bar=60; let r1=&mut bar; let r2=&mut bar;
let mut bar=60; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
for (num in list)
for (num of list)
for...in iterates keys.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
INSERT INTO products VALUES ('info',43)
INSERT INTO products (id, email) VALUES ('info',43);
Specify columns.
SQL
UPDATE items SET email='value' WHERE email=30
UPDATE items SET email='value' WHERE email=30;
Add semicolon.
SQL
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
switch(count){{ case 71: break; }}
switch(count){{ case 71: break; default: break; }}
Add default case.
Java
let item = 'data'
let item = "data"
Double quotes.
Swift
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
let x = 24; x += 1;
let mut x = 24; x += 1;
Need mut to modify.
Rust
let x = 27;
let x = 27;
Correct.
JavaScript
if (data = 50)
if (data == 50)
Use ==.
Scala
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
function handle() {{ return {{key:'result'}} }}
function handle() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
foo
foo()
Add parentheses.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
yield y
yield y
Correct yield.
Python
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(16);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(16);
Correct.
Node.js
95x = 10
x95 = 10
Variable cannot start with digit.
Python
<person age=100>
<person age="100">
Quote attribute.
XML
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
b == '70'
b === 70
Use strict equality.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
arr[17]
if (length(arr) >= 17) arr[17]
Check length.
R
val num = 52; num = 79
var num = 52; num = 79
Use var for reassignment.
Scala
function render(index) print(index) end
function render(index) print(index) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
if a > 9 print('info')
if a > 9: print('info')
Colon missing after if.
Python
WHERE name = '89'
WHERE name = 89
Don't quote integer.
SQL
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if ($b = 33)
if ($b == 33)
Use ==.
Perl
int num = 'test';
String num = 'test';
Type mismatch.
Dart
<person name='output'/>
<person name="output"/>
Double quotes.
XML
if y > 37 print('data')
if y > 37: print('data')
Colon missing after if.
Python
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(41);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(41);
Correct.
Node.js
INSERT INTO orders VALUES ('output',10)
INSERT INTO orders (age, role) VALUES ('output',10);
Specify columns.
SQL
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
while val > 8 val -= 1
while val > 8: val -= 1
Colon missing after while.
Python
'result' + 89
'result' + str(89)
Can't add int to string.
Python
{{'title':31, 'title' 39}}
{{'title':31, 'title':39}}
Colon missing.
Python
<person age=92>
<person age="92">
Quote attribute.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (temp = 66)
if (temp == 66)
Use ==.
Scala
List(100,99,98)
List(100,99,98)
Correct.
Scala
if ($b = 97)
if ($b == 97)
Use ==.
Perl
var val int = 'result'
var val string = 'result'
Type mismatch.
Go
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
json.sqrt(40)
import json json.sqrt(40)
Import module first.
Python
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP