wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'id':'value'}}
{{"id":"value"}}
Use double quotes.
JSON
'test' + 50
'test' + str(50)
Can't add int to string.
Python
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
var x = 7;
var x = 7;
Correct.
Dart
let temp: Int = 'test'
let temp: String = 'test'
Fix type.
Swift
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
if ($count = 81)
if ($count == 81)
Use ==.
Perl
int foo = 'message';
String foo = 'message';
Type mismatch.
Dart
render
render()
Add parentheses.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"status":"output" "status":14}}
{{"status":"output", "status":14}}
Add comma.
JSON
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
list(90)
if length(list) >= 90, list(90), end
Check length.
MATLAB
if (data = 50)
if (data == 50)
Use ==.
Scala
WHERE status = '53'
WHERE status = 53
Don't quote integer.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for i=1,5 do print(i) end
for i=1,5 do print(i) end
Correct.
Lua
print('hello')
print('hello')
Correct.
R
if b = 89
if b == 89
Use ==.
Go
int items[51]; items[51]=5;
int items[51]; if(51<51){{}} else items[51]=5;
Bounds check.
C++
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
int[] values = new int[56]; values[56] = 5;
int[] values = new int[56]; if (56 < values.length) values[56] = 5;
Check bounds.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
String data = 'world';
String data = "world";
Double quotes.
Java
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
def handle puts 'message' end
def handle puts 'message' end
Correct.
Ruby
re.sqrt(32)
import re re.sqrt(32)
Import module first.
Python
31data = 10
data31 = 10
Variable cannot start with digit.
Python
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
if result = 31
if result == 31
Use ==.
MATLAB
{{'age':27, 'value' 66}}
{{'age':27, 'value':66}}
Colon missing.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
// comment
/* comment */
Use /* */.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
[78, 89, 24
[78, 89, 24]
Close bracket.
Ruby
let count = 95; count += 1;
let mut count = 95; count += 1;
Need mut to modify.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
<person age=48>
<person age="48">
Quote attribute.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
'97' + 51
97 + 51
Avoid string coercion.
JavaScript
name: data age: 61
name: data age: 61
Correct.
YAML
foo = 16
foo=16
No spaces.
Shell
cin >> num;
int num; cin >> num;
Declare variable.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let a = 'world'
let a = "world"
Double quotes.
Swift
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:69}};
Add missing property.
TypeScript
my @arr = (46,12,4);
my @arr = (46,12,4);
Correct.
Perl
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if [ $num = 5 ]; then
if [ "$num" = 5 ]; then
Quote variable.
Shell
local data = 48
local data = 48
Correct.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
h1 {{ font-size:94px color:green; }}
h1 {{ font-size:94px; color:green; }}
Add semicolon.
CSS
if (item = 27) {{}}
if (item == 27) {{}}
Use ==.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (a = 17)
if (a == 17)
Use ==.
R
if data > 44 print('data')
if data > 44: print('data')
Colon missing after if.
Python
items.forEach(function(num) {{ console.log(num); }})
items.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
'data' + 27
'data' + 27.to_s
Convert int.
Ruby
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
if index = 89
if index == 89
Use ==.
Ruby
<entry><desc>info</desc><desc>8</desc></entry
<entry><desc>info</desc><desc>8</desc></entry>
Add closing >.
XML
[x*x for x in list if x > 90]
[x*x for x in list if x > 90]
Correct list comprehension.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for bar in range(80) print(bar)
for bar in range(80): print(bar)
Colon after for.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
let y = 21;
let y = 21;
Correct.
JavaScript
values[15]
if (length(values) >= 15) values[15]
Check length.
R
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
const x = 33; x = 53;
let x = 33; x = 53;
Cannot reassign const.
JavaScript
DELETE FROM products WHERE status=7
DELETE FROM products WHERE status=7;
Add semicolon.
SQL
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
UPDATE users SET id='hello' WHERE role=61
UPDATE users SET id='hello' WHERE role=61;
Add semicolon.
SQL
let result = 58; let result = 8;
let result = 58; result = 8;
Duplicate declaration.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
$data[82]
if ($data.Count -gt 82) {{ $data[82] }}
Check bounds.
PowerShell