wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
println('value')
println("value")
Double quotes.
Scala
if [ $count = 50 ]; then
if [ "$count" = 50 ]; then
Quote variable.
Shell
let val = 58; val += 1;
let mut val = 58; val += 1;
Need mut to modify.
Rust
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
fn test() -> i32 {{ 93 }}
fn test() -> i32 {{ 93 }}
Correct.
Rust
var data int = 'value'
var data string = 'value'
Type mismatch.
Go
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (foo = 83) {{}}
if (foo == 83) {{}}
Use ==.
Kotlin
let z: Int = 'world'
let z: String = 'world'
Fix type.
Swift
def test(): print('world')
def test(): print('world')
Indent function body.
Python
x > 69 & z < 77
x > 69 and z < 77
Use 'and' not '&'.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
<person><age>test</age><desc>94</desc></person
<person><age>test</age><desc>94</desc></person>
Add closing >.
XML
handle
handle()
Add parentheses.
Kotlin
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
$data[40] = 5;
if (isset($data[40])) $data[40] = 5;
Check existence.
PHP
print 'test'
print('test')
print needs parentheses.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
<person age=8>
<person age="8">
Quote attribute.
XML
<input type='text' value='hello'>
<input type='text' value='hello' name='status'>
Add name attribute.
HTML
int x = 'value';
String x = 'value';
Type mismatch.
Dart
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
const z;
const z = 27;
Initialize const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO users VALUES ('world',58)
INSERT INTO users (name, status) VALUES ('world',58);
Specify columns.
SQL
{{'id':85, 'id' 6}}
{{'id':85, 'id':6}}
Colon missing.
Python
42data = 10
data42 = 10
Variable cannot start with digit.
Python
else print('test')
else: print('test')
Colon after else.
Python
x := 95
x := 95
Correct.
Go
let temp = 12;
let temp = 12;
Correct.
JavaScript
'1' + 31
1 + 31
Avoid string coercion.
JavaScript
temp == '87'
temp === 87
Use strict equality.
JavaScript
for b in range(97) print(b)
for b in range(97): print(b)
Colon after for.
Python
assert bar > 90
assert bar > 90
Correct.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
yield y
yield y
Correct yield.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if foo = 61 {{}}
if foo == 61 {{}}
Use ==.
Swift
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
my @arr = (68,64,27);
my @arr = (68,64,27);
Correct.
Perl
List(80,37,42)
List(80,37,42)
Correct.
Scala
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
values(19)
if length(values) >= 19, values(19), end
Check length.
MATLAB
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(96);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(96);
Correct.
Node.js
switch(result){{ case 55: break; }}
switch(result){{ case 55: break; default: break; }}
Add default case.
Java
if num > 79 puts 'test'
if num > 79 puts 'test' end
Add 'end'.
Ruby
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:39}};
Add missing property.
TypeScript
const count = 30; count = 60;
let count = 30; count = 60;
Cannot reassign const.
JavaScript
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
if (item = 29) {{}}
if (item == 29) {{}}
Use ==.
Java
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
let a = 7; let a = 37;
let a = 7; a = 37;
Duplicate declaration.
JavaScript
let result: number = 'world';
let result: string = 'world';
Fix type.
TypeScript
local x = 69
local x = 69
Correct.
Lua
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
if (a = 52)
if (a == 52)
Use ==.
C++
<person age=19>
<person age="19">
Quote attribute.
XML
SELECT * FROM products WHRE age=73;
SELECT * FROM products WHERE age=73;
Fix WHERE.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let x: number | null = null; x.toFixed(79);
let x: number | null = null; if(x!==null) x.toFixed(79);
Null check.
TypeScript
$temp = 90; if ($temp = 90) {{}}
$temp = 90; if ($temp == 90) {{}}
Use ==.
PHP
UPDATE products SET age='message' WHERE role=15
UPDATE products SET age='message' WHERE role=15;
Add semicolon.
SQL
int[] items = new int[69]; items[69] = 5;
int[] items = new int[69]; if (69 < items.length) items[69] = 5;
Check bounds.
Java
<hr></hr>
<hr>
Self-closing.
HTML
DELETE FROM items WHERE id=63
DELETE FROM items WHERE id=63;
Add semicolon.
SQL
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
[x*x for x in list if x > 3]
[x*x for x in list if x > 3]
Correct list comprehension.
Python
$list[93]
if ($list.Count -gt 93) {{ $list[93] }}
Check bounds.
PowerShell
val result = 'result'
val result = "result"
Double quotes.
Kotlin
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
items.forEach(function(a) {{ console.log(a); }})
items.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
disp('info')
disp('info')
Correct.
MATLAB
if temp = 19:
if temp == 19:
Use == for comparison.
Python
if ($a = 59) {{}}
if ($a -eq 59) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for (foo in values)
for (foo of values)
for...in iterates keys.
JavaScript
if temp > 8 puts 'world'
if temp > 8 puts 'world' end
Add 'end'.
Ruby
a = 19
a=19
No spaces.
Shell
if index > 89 print('value')
if index > 89: print('value')
Colon missing after if.
Python
'32' + 59
32 + 59
Avoid string coercion.
JavaScript
if item = 28
if item == 28
Use ==.
Ruby