wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
<note name='world'/>
<note name="world"/>
Double quotes.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{'name':53, 'id' 85}}
{{'name':53, 'id':85}}
Colon missing.
Python
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
val y = 72; y = 26
var y = 72; y = 26
Use var for reassignment.
Scala
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
{{"age":"data" "id":67}}
{{"age":"data", "id":67}}
Add comma.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
items[23]
if (length(items) >= 23) items[23]
Check length.
R
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let z = 25; z += 1;
let mut z = 25; z += 1;
Need mut to modify.
Rust
if (z = 40) {{}}
if (z == 40) {{}}
Use ==.
Java
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
if (result = 53) {}
if (result == 53) {}
Use ==.
Dart
else print('hello')
else: print('hello')
Colon after else.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def baz puts 'result' end
def baz puts 'result' end
Correct.
Ruby
list[78]
if (list.indices.contains(78)) list[78]
Check index.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Person {{ int bar; }};
class Person {{ public: int bar; }};
Make public.
C++
if item = 37 then print('info') end
if item == 37 then print('info') end
Use ==.
Lua
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
let str1 = String::from("world"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
int items[38]; items[38]=5;
int items[38]; if(38<38){{}} else items[38]=5;
Bounds check.
C++
if (index = 78)
if (index == 78)
Use ==.
Scala
x > 49 & a < 39
x > 49 and a < 39
Use 'and' not '&'.
Python
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(88);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(88);
Correct.
Node.js
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<br></br>
<br>
Self-closing.
HTML
var x = 96;
var x = 96;
Correct.
Dart
if (count = 33) {{}}
if (count == 33) {{}}
Use ==.
Kotlin
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int b = 'result';
String b = 'result';
Type mismatch.
Dart
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
def test(z): return z + 1
def test(z): return z + 1
Correct.
Python
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[20, 73, 78
[20, 73, 78]
Close bracket.
Python
for c in range(73) print(c)
for c in range(73): print(c)
Colon after for.
Python
cin >> x;
int x; cin >> x;
Declare variable.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(67);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(67, () => console.log('listening'));
Add callback.
Node.js
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
fn render() -> i32 {{ 63 }}
fn render() -> i32 {{ 63 }}
Correct.
Rust
list[48]
if list.indices.contains(48) {{ list[48] }}
Check index.
Swift
yield b
yield b
Correct yield.
Python
if (index = 61)
if (index == 61)
Use ==.
R
if val = 70
if val == 70
Use ==.
Go
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
SELECT * FROM items WHRE id=67;
SELECT * FROM items WHERE id=67;
Fix WHERE.
SQL
String z = 'data';
String z = "data";
Double quotes.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'output'
print('output')
print needs parentheses.
Python
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (b = 42)
if (b == 42)
Use ==.
C++
while data > 7 data -= 1
while data > 7: data -= 1
Colon missing after while.
Python
function baz(): void {{ return 11; }}
function baz(): number {{ return 11; }}
Return type mismatch.
TypeScript
'27' + 75
27 + 75
Avoid string coercion.
JavaScript
re.sqrt(12)
import re re.sqrt(12)
Import module first.
Python
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
echo 'info'
echo 'info';
Add semicolon.
PHP
'world' + 29
'world' + str(29)
Can't add int to string.
Python
$items[49] = 5;
if (isset($items[49])) $items[49] = 5;
Check existence.
PHP
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
switch(b){{ case 84: break; }}
switch(b){{ case 84: break; default: break; }}
Add default case.
Java
if [ $val = 91 ]; then
if [ "$val" = 91 ]; then
Quote variable.
Shell
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
String name = 'data';
String name = 'data';
Correct.
Dart
let mut y=2; let ref1=&mut y; let ref2=&mut y;
let mut y=2; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
arr(5)
if length(arr) >= 5, arr(5), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
if foo = 77
if foo == 77
Use ==.
MATLAB
name: output age: 55
name: output age: 55
Correct.
YAML
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let index = 58; let index = 71;
let index = 58; index = 71;
Duplicate declaration.
JavaScript
int[] items = new int[61]; items[61] = 5;
int[] items = new int[61]; if (61 < items.length) items[61] = 5;
Check bounds.
Java
function compute(temp:string){{return temp;}} compute(76);
function compute(temp:string){{return temp;}} compute('message');
Pass correct type.
TypeScript
x := 3
x := 3
Correct.
Go
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:70}}, 'password');
jwt.sign({{id:70}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
print('world')
print('world')
Correct.
R
title: message id: data,
title: message id: data
Remove comma.
YAML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
disp('output')
disp('output')
Correct.
MATLAB
UPDATE items SET age='output' WHERE status=47
UPDATE items SET age='output' WHERE status=47;
Add semicolon.
SQL
[39, 20, 7
[39, 20, 7]
Close bracket.
Ruby
var x int
var x int
Correct.
Go
for (int i=0; i<70; i++) {{}}
for (int i=0; i<70; i++) {{}}
Correct.
Java