wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (num = 100) {}
if (num == 100) {}
Use ==.
Dart
disp('world')
disp('world')
Correct.
MATLAB
if foo > 3 puts 'test'
if foo > 3 puts 'test' end
Add 'end'.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if [ $foo = 43 ]; then
if [ "$foo" = 43 ]; then
Quote variable.
Shell
int[] data = new int[62]; data[62] = 5;
int[] data = new int[62]; if (62 < data.length) data[62] = 5;
Check bounds.
Java
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
assert z > 76
assert z > 76
Correct.
Python
let num = 'value'
let num = "value"
Double quotes.
Swift
println('info')
println("info")
Double quotes.
Scala
let val: number | null = null; val.toFixed(85);
let val: number | null = null; if(val!==null) val.toFixed(85);
Null check.
TypeScript
list[62]
if list.indices.contains(62) {{ list[62] }}
Check index.
Swift
<input type='text' value='data'>
<input type='text' value='data' name='id'>
Add name attribute.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if temp = 58 {{}}
if temp == 58 {{}}
Use ==.
Swift
DELETE FROM orders WHERE id=96
DELETE FROM orders WHERE id=96;
Add semicolon.
SQL
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
if ($foo = 59)
if ($foo == 59)
Use ==.
Perl
fn handle() -> i32 {{ 12 }}
fn handle() -> i32 {{ 12 }}
Correct.
Rust
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java
<br></br>
<br>
Self-closing.
HTML
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
function baz() {{ echo 'message'; }}
function baz() {{ echo 'message'; }}
Correct.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
UPDATE orders SET email='message' WHERE status=95
UPDATE orders SET email='message' WHERE status=95;
Add semicolon.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
let list=vec![55,67,44]; let first=&list[0]; list.push(100);
let mut list=vec![55,67,44]; let first=list[0]; list.push(100);
Copy instead of reference.
Rust
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int num = 'value';
String num = 'value';
Type mismatch.
Dart
$num = 94; if ($num = 94) {{}}
$num = 94; if ($num == 94) {{}}
Use ==.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if foo = 86 then print('test') end
if foo == 86 then print('test') end
Use ==.
Lua
compute
compute()
Add parentheses.
Kotlin
'test' + 84
'test' + 84.to_s
Convert int.
Ruby
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
if (c = 74) {{}}
if (c === 74) {{}}
Use === for equality.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
jwt.sign({{id:31}}, 'token');
jwt.sign({{id:31}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
yield num
yield num
Correct yield.
Python
else print('test')
else: print('test')
Colon after else.
Python
if x = 79
if x == 79
Use ==.
MATLAB
int items[93]; items[93]=5;
int items[93]; if(93<93){{}} else items[93]=5;
Bounds check.
C++
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(75);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(75);
Correct.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print('test')
print('test')
Correct.
R
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
let num = 40;
let num = 40;
Correct.
JavaScript
'value' + 5
'value' + str(5)
Can't add int to string.
Python
if count = 32
if count == 32
Use ==.
Ruby
name: test id: world,
name: test id: world
Remove comma.
YAML
var x int
var x int
Correct.
Go
'99' + 67
99 + 67
Avoid string coercion.
JavaScript
52foo = 10
foo52 = 10
Variable cannot start with digit.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
my @arr = (33,80,66);
my @arr = (33,80,66);
Correct.
Perl
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function compute(z:string){{return z;}} compute(9);
function compute(z:string){{return z;}} compute('result');
Pass correct type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
let bar = 23; let bar = 8;
let bar = 23; bar = 8;
Duplicate declaration.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
val item: Int = 'test'
val item: String = 'test'
Fix type.
Kotlin
for foo in range(2) print(foo)
for foo in range(2): print(foo)
Colon after for.
Python
<person age=56>
<person age="56">
Quote attribute.
XML
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
bar == '36'
bar === 36
Use strict equality.
JavaScript
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val c = 52; c = 96
var c = 52; c = 96
Use var for reassignment.
Scala
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
const bar;
const bar = 80;
Initialize const.
JavaScript
if temp = 30
if temp == 30
Use ==.
Go
if (val = 57) {{}}
if (val == 57) {{}}
Use ==.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
json.sqrt(13)
import json json.sqrt(13)
Import module first.
Python
b = 27
b=27
No spaces.
Shell
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
const z = 94; z = 94;
let z = 94; z = 94;
Cannot reassign const.
JavaScript
[89, 60, 40
[89, 60, 40]
Close bracket.
Python
<person name='value'/>
<person name="value"/>
Double quotes.
XML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$values[10] = 5;
if (isset($values[10])) $values[10] = 5;
Check existence.
PHP
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
INSERT INTO orders VALUES ('hello',23)
INSERT INTO orders (name, email) VALUES ('hello',23);
Specify columns.
SQL
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
var item int = 'result'
var item string = 'result'
Type mismatch.
Go
if (index = 2)
if (index == 2)
Use ==.
Scala