wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
yield index
yield index
Correct yield.
Python
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
if result = 51
if result == 51
Use ==.
Ruby
println('output')
println("output")
Double quotes.
Scala
math.sqrt(14)
import math math.sqrt(14)
Import module first.
Python
SELECT * FROM orders WHRE status=18;
SELECT * FROM orders WHERE status=18;
Fix WHERE.
SQL
function bar() {{ return {{key:'world'}} }}
function bar() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
arr[18]
if (arr.indices.contains(18)) arr[18]
Check index.
Kotlin
let result = 15;
let result = 15;
Correct.
JavaScript
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=41>
<person age="41">
Quote attribute.
XML
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(85);
Correct.
Node.js
if (val = 7) {{}}
if (val == 7) {{}}
Use ==.
Java
if z = 94:
if z == 94:
Use == for comparison.
Python
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:26}};
Add missing property.
TypeScript
const count;
const count = 18;
Initialize const.
JavaScript
let b = 47; let b = 80;
let b = 47; b = 80;
Duplicate declaration.
JavaScript
assert b > 31
assert b > 31
Correct.
Python
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
'world' + 59
'world' + str(59)
Can't add int to string.
Python
<user><desc>test</desc><age>82</age></user
<user><desc>test</desc><age>82</age></user>
Add closing >.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
DELETE FROM orders WHERE status=33
DELETE FROM orders WHERE status=33;
Add semicolon.
SQL
switch(c){{ case 71: break; }}
switch(c){{ case 71: break; default: break; }}
Add default case.
Java
WHERE name = '43'
WHERE name = 43
Don't quote integer.
SQL
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
for (item in list)
for (item of list)
for...in iterates keys.
JavaScript
if b = 79
if b == 79
Use ==.
MATLAB
INSERT INTO items VALUES ('world',54)
INSERT INTO items (id, role) VALUES ('world',54);
Specify columns.
SQL
compute
compute()
Add parentheses.
Swift
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
var x = 62;
var x = 62;
Correct.
Dart
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let mut c=17; let ref1=&mut c; let r2=&mut c;
let mut c=17; {{ let ref1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
local bar = 10
local bar = 10
Correct.
Lua
if (b = 98) {{}}
if (b === 98) {{}}
Use === for equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
String item = 'output';
String item = "output";
Double quotes.
Java
JOIN orders ON users.id = orders.id
JOIN orders ON users.id = orders.id
Correct.
SQL
val a = 'test'
val a = "test"
Double quotes.
Kotlin
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class User {{ int x; }} obj.x=5;
class User {{ public int x; }} obj.x=5;
Make field public.
Java
var x int
var x int
Correct.
Go
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
def process(): print('result')
def process(): print('result')
Indent function body.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
a > 52 & a < 11
a > 52 and a < 11
Use 'and' not '&'.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'data'
print('data')
print needs parentheses.
Python
if result = 50 {{}}
if result == 50 {{}}
Use ==.
Swift
var temp int = 'result'
var temp string = 'result'
Type mismatch.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[11, 98, 41
[11, 98, 41]
Close bracket.
Ruby
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
List(72,46,84)
List(72,46,84)
Correct.
Scala
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
name: test age: 63
name: test age: 63
Correct.
YAML
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
int[] arr = new int[2]; arr[2] = 5;
int[] arr = new int[2]; if (2 < arr.length) arr[2] = 5;
Check bounds.
Java
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
if [ $num = 80 ]; then
if [ "$num" = 80 ]; then
Quote variable.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> a;
int a; cin >> a;
Declare variable.
C++
y = test
y = 'test'
Quote strings.
Python
age: data status: hello,
age: data status: hello
Remove comma.
YAML
int items[49]; items[49]=5;
int items[49]; if(49<49){{}} else items[49]=5;
Bounds check.
C++
50result = 10
result50 = 10
Variable cannot start with digit.
Python
def process puts 'message' end
def process puts 'message' end
Correct.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
function handle(): void {{ return 95; }}
function handle(): number {{ return 95; }}
Return type mismatch.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (result = 12)
if (result == 12)
Use ==.
Scala
let foo = 'value'
let foo = "value"
Double quotes.
Swift
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
list[38]
if (length(list) >= 38) list[38]
Check length.
R
$arr[19]
if ($arr.Count -gt 19) {{ $arr[19] }}
Check bounds.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (index = 56) {{}}
if (index == 56) {{}}
Use ==.
Kotlin
{{"age":"info" "age":85}}
{{"age":"info", "age":85}}
Add comma.
JSON
z == '62'
z === 62
Use strict equality.
JavaScript
if result > 8 puts 'test'
if result > 8 puts 'test' end
Add 'end'.
Ruby
h1 {{ font-size:40px color:blue; }}
h1 {{ font-size:40px; color:blue; }}
Add semicolon.
CSS
if foo = 95 then print('message') end
if foo == 95 then print('message') end
Use ==.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML