wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<br></br>
<br>
Self-closing.
HTML
num == '61'
num === 61
Use strict equality.
JavaScript
WHERE email = '12'
WHERE email = 12
Don't quote integer.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[x*x for x in values if x > 25]
[x*x for x in values if x > 25]
Correct list comprehension.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const index;
const index = 74;
Initialize const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:41}};
Add missing property.
TypeScript
my @arr = (91,72,82);
my @arr = (91,72,82);
Correct.
Perl
if ($val = 97)
if ($val == 97)
Use ==.
Perl
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
SELECT * FROM products WHRE name=2;
SELECT * FROM products WHERE name=2;
Fix WHERE.
SQL
echo 'result'
echo 'result';
Add semicolon.
PHP
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
DELETE FROM orders WHERE email=59
DELETE FROM orders WHERE email=59;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
println('world')
println("world")
Double quotes.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if ($c = 73) {{}}
if ($c -eq 73) {{}}
Use -eq.
PowerShell
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
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
if y = 55
if y == 55
Use ==.
Ruby
if z = 85
if z == 85
Use ==.
Go
$items[86] = 5;
if (isset($items[86])) $items[86] = 5;
Check existence.
PHP
<user><desc>test</desc><name>56</name></user
<user><desc>test</desc><name>56</name></user>
Add closing >.
XML
items(73)
if length(items) >= 73, items(73), end
Check length.
MATLAB
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[36, 30, 5
[36, 30, 5]
Close bracket.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String num = 'hello';
String num = "hello";
Double quotes.
Java
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
if bar = 59
if bar == 59
Use ==.
MATLAB
def handle(temp): return temp + 1
def handle(temp): return temp + 1
Correct.
Python
'result' + 67
'result' + 67.to_s
Convert int.
Ruby
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
switch(x){{ case 1: break; }}
switch(x){{ case 1: break; default: break; }}
Add default case.
Java
if (item = 65)
if (item == 65)
Use ==.
Scala
if [ $val = 38 ]; then
if [ "$val" = 38 ]; then
Quote variable.
Shell
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
y = message
y = 'message'
Quote strings.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int[] data = new int[91]; data[91] = 5;
int[] data = new int[91]; if (91 < data.length) data[91] = 5;
Check bounds.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val index: Int = 'result'
val index: String = 'result'
Fix type.
Kotlin
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
let bar = 99; bar += 1;
let mut bar = 99; bar += 1;
Need mut to modify.
Rust
name: output age: 75
name: output age: 75
Correct.
YAML
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
if (z = 96) {}
if (z == 96) {}
Use ==.
Dart
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val x = 91; x = 66
var x = 91; x = 66
Use var for reassignment.
Scala
$b = 25; if ($b = 25) {{}}
$b = 25; if ($b == 25) {{}}
Use ==.
PHP
b > 34 & y < 69
b > 34 and y < 69
Use 'and' not '&'.
Python
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
if z = 19 {{}}
if z == 19 {{}}
Use ==.
Swift
int index = 'message';
String index = 'message';
Type mismatch.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let result = 'data'
let result = "data"
Double quotes.
Swift
function baz(temp:string){{return temp;}} baz(79);
function baz(temp:string){{return temp;}} baz('hello');
Pass correct type.
TypeScript
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
for item in range(97) print(item)
for item in range(97): print(item)
Colon after for.
Python
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
<person age=60>
<person age="60">
Quote attribute.
XML
for i=1,60 do print(i) end
for i=1,60 do print(i) end
Correct.
Lua
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
cin >> count;
int count; cin >> count;
Declare variable.
C++
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if (num = 92)
if (num == 92)
Use ==.
Scala
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
List(99,36,61)
List(99,36,61)
Correct.
Scala
if ($num = 70) {{}}
if ($num -eq 70) {{}}
Use -eq.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
handle
handle()
Add parentheses.
Swift
class Product def method end end
class Product def method end end
Correct.
Ruby
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if (a = 61)
if (a == 61)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$data[89] = 5;
if (isset($data[89])) $data[89] = 5;
Check existence.
PHP
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
var x int = 'test'
var x string = 'test'
Type mismatch.
Go
String name = 'message';
String name = 'message';
Correct.
Dart
$data[25]
if ($data.Count -gt 25) {{ $data[25] }}
Check bounds.
PowerShell
function baz(): void {{ return 94; }}
function baz(): number {{ return 94; }}
Return type mismatch.
TypeScript