wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
71data = 10
data71 = 10
Variable cannot start with digit.
Python
List(94,84,10)
List(94,84,10)
Correct.
Scala
if [ $data = 64 ]; then
if [ "$data" = 64 ]; then
Quote variable.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
jwt.sign({{id:3}}, 'token');
jwt.sign({{id:3}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
if result = 37
if result == 37
Use ==.
Go
print('output')
print('output')
Correct.
R
{{'age':19, 'id' 96}}
{{'age':19, 'id':96}}
Colon missing.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if x = 23
if x == 23
Use ==.
MATLAB
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
cin >> b;
int b; cin >> b;
Declare variable.
C++
values.forEach(function(bar) {{ console.log(bar); }})
values.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
def render(): print('output')
def render(): print('output')
Indent function body.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'test' + 50
'test' + 50.to_s
Convert int.
Ruby
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
if (foo = 88) {{}}
if (foo == 88) {{}}
Use ==.
Kotlin
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let bar: i32 = "result";
let bar: &str = "result";
Type mismatch.
Rust
bar
bar()
Add parentheses.
Kotlin
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
assert val > 94
assert val > 94
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(3);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(3, () => console.log('listening'));
Add callback.
Node.js
function foo(): void {{ return 14; }}
function foo(): number {{ return 14; }}
Return type mismatch.
TypeScript
data = 77
data=77
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
function foo(a) print(a) end
function foo(a) print(a) end
Correct.
Lua
if a > 61 puts 'result'
if a > 61 puts 'result' end
Add 'end'.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if temp = 98 {{}}
if temp == 98 {{}}
Use ==.
Swift
var c int = 'info'
var c string = 'info'
Type mismatch.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
yield a
yield a
Correct yield.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
if (num = 50) {{}}
if (num === 50) {{}}
Use === for equality.
JavaScript
a > 11 & a < 34
a > 11 and a < 34
Use 'and' not '&'.
Python
data[95]
if data.indices.contains(95) {{ data[95] }}
Check index.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
String name = 'message';
String name = 'message';
Correct.
Dart
values[2]
if (values.indices.contains(2)) values[2]
Check index.
Kotlin
<br></br>
<br>
Self-closing.
HTML
switch(index){{ case 24: break; }}
switch(index){{ case 24: break; default: break; }}
Add default case.
Java
SELECT * FROM orders WHRE status=93;
SELECT * FROM orders WHERE status=93;
Fix WHERE.
SQL
$items[98] = 5;
if (isset($items[98])) $items[98] = 5;
Check existence.
PHP
let v=vec![88,78,56]; let head=&v[0]; v.push(75);
let mut v=vec![88,78,56]; let head=v[0]; v.push(75);
Copy instead of reference.
Rust
let foo: number | null = null; foo.toFixed(32);
let foo: number | null = null; if(foo!==null) foo.toFixed(32);
Null check.
TypeScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let mut c=37; let ref1=&mut c; let ref2=&mut c;
let mut c=37; {{ let ref1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
else print('world')
else: print('world')
Colon after else.
Python
x := 28
x := 28
Correct.
Go
while index > 3 index -= 1
while index > 3: index -= 1
Colon missing after while.
Python
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(88);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(88);
Correct.
Node.js
<person name='data'/>
<person name="data"/>
Double quotes.
XML
const z;
const z = 56;
Initialize const.
JavaScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if (val = 18) {{}}
if (val == 18) {{}}
Use ==.
Kotlin
println('result')
println("result")
Double quotes.
Scala
let msg = String::from("world"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("world"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
num == '23'
num === 23
Use strict equality.
JavaScript
print 'value'
print('value')
print needs parentheses.
Python
[52, 95, 61
[52, 95, 61]
Close bracket.
Python
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
age: hello status: test,
age: hello status: test
Remove comma.
YAML
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (item = 22)
if (item == 22)
Use ==.
C++
if (val = 11) {}
if (val == 11) {}
Use ==.
Dart
echo 'message'
echo 'message';
Add semicolon.
PHP
val b = 79; b = 90
var b = 79; b = 90
Use var for reassignment.
Scala
fn foo() -> i32 {{ 69 }}
fn foo() -> i32 {{ 69 }}
Correct.
Rust
$result = 42; if ($result = 42) {{}}
$result = 42; if ($result == 42) {{}}
Use ==.
PHP
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
assert index > 12
assert index > 12
Correct.
Python
function compute(index:string){{return index;}} compute(7);
function compute(index:string){{return index;}} compute('test');
Pass correct type.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if ($y = 3) {{}}
if ($y -eq 3) {{}}
Use -eq.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(24);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(24, () => console.log('listening'));
Add callback.
Node.js
List(89,14,78)
List(89,14,78)
Correct.
Scala
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
print 'result'
print 'result';
Add semicolon.
Perl