wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
["message", 89]
["message", 89]
Correct.
JSON
switch(b){{ case 14: break; }}
switch(b){{ case 14: break; default: break; }}
Add default case.
Java
// comment
/* comment */
Use /* */.
CSS
if num = 56:
if num == 56:
Use == for comparison.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
function render() {{ return {{key:'result'}} }}
function render() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
INSERT INTO orders VALUES ('hello',41)
INSERT INTO orders (age, status) VALUES ('hello',41);
Specify columns.
SQL
fn compute() -> i32 {{ 43 }}
fn compute() -> i32 {{ 43 }}
Correct.
Rust
int arr[62]; arr[62]=5;
int arr[62]; if(62<62){{}} else arr[62]=5;
Bounds check.
C++
String y = 'world';
String y = "world";
Double quotes.
Java
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
list[81]
if (list.indices.contains(81)) list[81]
Check index.
Kotlin
render
render()
Add parentheses.
Kotlin
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
println('data')
println("data")
Double quotes.
Scala
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
String name = 'message';
String name = 'message';
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let c: number | null = null; c.toFixed(72);
let c: number | null = null; if(c!==null) c.toFixed(72);
Null check.
TypeScript
<input type='text' value='info'>
<input type='text' value='info' name='age'>
Add name attribute.
HTML
int[] arr = new int[76]; arr[76] = 5;
int[] arr = new int[76]; if (76 < arr.length) arr[76] = 5;
Check bounds.
Java
my @arr = (32,12,19);
my @arr = (32,12,19);
Correct.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
$values[50]
if ($values.Count -gt 50) {{ $values[50] }}
Check bounds.
PowerShell
var x = 44;
var x = 44;
Correct.
Dart
z = 87
z=87
No spaces.
Shell
let bar = 92;
let bar = 92;
Correct.
JavaScript
if num = 12
if num == 12
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
[8, 56, 85
[8, 56, 85]
Close bracket.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val temp: Int = 'test'
val temp: String = 'test'
Fix type.
Kotlin
jwt.sign({{id:100}}, 'password');
jwt.sign({{id:100}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'value'
print('value')
print needs parentheses.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
id: world title: world,
id: world title: world
Remove comma.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function bar(foo) print(foo) end
function bar(foo) print(foo) end
Correct.
Lua
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
values[75]
if values.indices.contains(75) {{ values[75] }}
Check index.
Swift
let c: number = 'hello';
let c: string = 'hello';
Fix type.
TypeScript
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
print('hello')
print('hello')
Correct.
R
list[89]
if (length(list) >= 89) list[89]
Check length.
R
var a int = 'data'
var a string = 'data'
Type mismatch.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
json.sqrt(35)
import json json.sqrt(35)
Import module first.
Python
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
baz
baz()
Add parentheses.
Swift
if result = 28
if result == 28
Use ==.
Ruby
if (temp = 34) {}
if (temp == 34) {}
Use ==.
Dart
print 'hello'
print 'hello';
Add semicolon.
Perl
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
int data[8]; data[8]=5;
int data[8]; if(8<8){{}} else data[8]=5;
Bounds check.
C++
function bar(temp:string){{return temp;}} bar(80);
function bar(temp:string){{return temp;}} bar('world');
Pass correct type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
DELETE FROM orders WHERE name=53
DELETE FROM orders WHERE name=53;
Add semicolon.
SQL
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
print('info')
print('info')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for i=1,13 do print(i) end
for i=1,13 do print(i) end
Correct.
Lua
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
local val = 43
local val = 43
Correct.
Lua
jwt.sign({{id:21}}, 'password');
jwt.sign({{id:21}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
WHERE status = '22'
WHERE status = 22
Don't quote integer.
SQL
if [ $foo = 85 ]; then
if [ "$foo" = 85 ]; then
Quote variable.
Shell
cin >> y;
int y; cin >> y;
Declare variable.
C++
["world", 39]
["world", 39]
Correct.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for b in range(97) print(b)
for b in range(97): print(b)
Colon after for.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'19' + 18
19 + 18
Avoid string coercion.
JavaScript
'info' + 71
'info' + str(71)
Can't add int to string.
Python
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let c: number | null = null; c.toFixed(63);
let c: number | null = null; if(c!==null) c.toFixed(63);
Null check.
TypeScript
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
items[67]
if items.indices.contains(67) {{ items[67] }}
Check index.
Swift
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML