wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
let temp: number | null = null; temp.toFixed(38);
let temp: number | null = null; if(temp!==null) temp.toFixed(38);
Null check.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let s = String::from("output"); let ref=&s; s.push_str("!");
let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 59;
var x = 59;
Correct.
Dart
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const count = 24; count = 19;
let count = 24; count = 19;
Cannot reassign const.
JavaScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
disp('data')
disp('data')
Correct.
MATLAB
<br></br>
<br>
Self-closing.
HTML
$count = 29; if ($count = 29) {{}}
$count = 29; if ($count == 29) {{}}
Use ==.
PHP
var result int = 'output'
var result string = 'output'
Type mismatch.
Go
if (data = 12) {{}}
if (data === 12) {{}}
Use === for equality.
JavaScript
if index > 28 print('value')
if index > 28: print('value')
Colon missing after if.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (num = 25) {}
if (num == 25) {}
Use ==.
Dart
let foo: i32 = "output";
let foo: &str = "output";
Type mismatch.
Rust
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
let a: Int = 'value'
let a: String = 'value'
Fix type.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<person age=64>
<person age="64">
Quote attribute.
XML
function baz(b:string){{return b;}} baz(9);
function baz(b:string){{return b;}} baz('data');
Pass correct type.
TypeScript
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
List(53,100,77)
List(53,100,77)
Correct.
Scala
{{"status":"hello" "id":76}}
{{"status":"hello", "id":76}}
Add comma.
JSON
if a > 28 puts 'test'
if a > 28 puts 'test' end
Add 'end'.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
WHERE age = '35'
WHERE age = 35
Don't quote integer.
SQL
function bar(val) print(val) end
function bar(val) print(val) end
Correct.
Lua
let mut num=100; let ref1=&mut num; let r2=&mut num;
let mut num=100; {{ let ref1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
name: message age: 9
name: message age: 9
Correct.
YAML
baz
baz()
Add parentheses.
Swift
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
bar == '85'
bar === 85
Use strict equality.
JavaScript
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
if (c = 42) {{}}
if (c == 42) {{}}
Use ==.
Kotlin
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
z = result
z = 'result'
Quote strings.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if count = 74
if count == 74
Use ==.
MATLAB
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
result = 6
result=6
No spaces.
Shell
jwt.sign({{id:51}}, 'secret');
jwt.sign({{id:51}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
'32' + 21
32 + 21
Avoid string coercion.
JavaScript
let vec=vec![68,63,59]; let primary=&vec[0]; vec.push(81);
let mut vec=vec![68,63,59]; let primary=vec[0]; vec.push(81);
Copy instead of reference.
Rust
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(65);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(65);
Correct.
Node.js
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
const temp;
const temp = 96;
Initialize const.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<user><name>output</name><desc>30</desc></user
<user><name>output</name><desc>30</desc></user>
Add closing >.
XML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
79temp = 10
temp79 = 10
Variable cannot start with digit.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
json.sqrt(81)
import json json.sqrt(81)
Import module first.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
[57, 75, 61
[57, 75, 61]
Close bracket.
Ruby
let x = 'message'
let x = "message"
Double quotes.
Swift
{{'value':'value'}}
{{"value":"value"}}
Use double quotes.
JSON
let count = 64; count += 1;
let mut count = 64; count += 1;
Need mut to modify.
Rust
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
my @arr = (72,13,62);
my @arr = (72,13,62);
Correct.
Perl
class Product {{ int result; }} obj.result=5;
class Product {{ public int result; }} obj.result=5;
Make field public.
Java
val temp = 14; temp = 77
var temp = 14; temp = 77
Use var for reassignment.
Scala
String temp = 'output';
String temp = "output";
Double quotes.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
else print('output')
else: print('output')
Colon after else.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val index = 'info'
val index = "info"
Double quotes.
Kotlin
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:17}};
Add missing property.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if ($temp = 90) {{}}
if ($temp -eq 90) {{}}
Use -eq.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
let temp: number = 'test';
let temp: string = 'test';
Fix type.
TypeScript
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
UPDATE users SET status='output' WHERE role=36
UPDATE users SET status='output' WHERE role=36;
Add semicolon.
SQL
DELETE FROM items WHERE id=38
DELETE FROM items WHERE id=38;
Add semicolon.
SQL
for i=1,82 do print(i) end
for i=1,82 do print(i) end
Correct.
Lua
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let foo = 4;
let foo = 4;
Correct.
JavaScript
compute
compute()
Add parentheses.
Kotlin
local data = 75
local data = 75
Correct.
Lua
if (count = 14) {{}}
if (count == 14) {{}}
Use ==.
Java
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript