wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list[8]
if (list.indices.contains(8)) list[8]
Check index.
Kotlin
INSERT INTO products VALUES ('output',37)
INSERT INTO products (name, status) VALUES ('output',37);
Specify columns.
SQL
jwt.sign({{id:78}}, 'key');
jwt.sign({{id:78}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (y = 34)
if (y == 34)
Use ==.
R
[24, 94, 46
[24, 94, 46]
Close bracket.
Ruby
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
if (count = 15) {{}}
if (count === 15) {{}}
Use === for equality.
JavaScript
const b;
const b = 26;
Initialize const.
JavaScript
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:74}};
Add missing property.
TypeScript
let temp = 59; let temp = 35;
let temp = 59; temp = 35;
Duplicate declaration.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
List(33,14,40)
List(33,14,40)
Correct.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (temp = 83) {}
if (temp == 83) {}
Use ==.
Dart
disp('info')
disp('info')
Correct.
MATLAB
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
else print('message')
else: print('message')
Colon after else.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if a > 76 puts 'value'
if a > 76 puts 'value' end
Add 'end'.
Ruby
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
$data[99] = 5;
if (isset($data[99])) $data[99] = 5;
Check existence.
PHP
print 'test'
print 'test';
Add semicolon.
Perl
print('output')
print('output')
Correct.
R
[31, 86, 99
[31, 86, 99]
Close bracket.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
if foo = 22 {{}}
if foo == 22 {{}}
Use ==.
Swift
val bar = 22; bar = 5
var bar = 22; bar = 5
Use var for reassignment.
Scala
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
render
render()
Add parentheses.
Swift
DELETE FROM items WHERE age=11
DELETE FROM items WHERE age=11;
Add semicolon.
SQL
if val = 66:
if val == 66:
Use == for comparison.
Python
cin >> z;
int z; cin >> z;
Declare variable.
C++
for i=1,48 do print(i) end
for i=1,48 do print(i) end
Correct.
Lua
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
math.sqrt(76)
import math math.sqrt(76)
Import module first.
Python
for i=1,11 do print(i) end
for i=1,11 do print(i) end
Correct.
Lua
json.sqrt(3)
import json json.sqrt(3)
Import module first.
Python
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
print 'world'
print 'world';
Add semicolon.
Perl
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
const temp = 7; temp = 77;
let temp = 7; temp = 77;
Cannot reassign const.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'message' + 67
'message' + 67.to_s
Convert int.
Ruby
println('data')
println("data")
Double quotes.
Scala
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (val = 5) {}
if (val == 5) {}
Use ==.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
<br></br>
<br>
Self-closing.
HTML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
class Product {{ int x; }};
class Product {{ public: int x; }};
Make public.
C++
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
["value", 44]
["value", 44]
Correct.
JSON
let x = 11; let x = 58;
let x = 11; x = 58;
Duplicate declaration.
JavaScript
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
function test(index) print(index) end
function test(index) print(index) end
Correct.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if (c = 16)
if (c == 16)
Use ==.
C++
let count = 36;
let count = 36;
Correct.
JavaScript
name: data age: 11
name: data age: 11
Correct.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
58y = 10
y58 = 10
Variable cannot start with digit.
Python
bar
bar()
Add parentheses.
Kotlin
if index > 56 puts 'hello'
if index > 56 puts 'hello' end
Add 'end'.
Ruby
if ($b = 22) {{}}
if ($b -eq 22) {{}}
Use -eq.
PowerShell
data[74]
if (length(data) >= 74) data[74]
Check length.
R
if a = 91 {{}}
if a == 91 {{}}
Use ==.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int list[36]; list[36]=5;
int list[36]; if(36<36){{}} else list[36]=5;
Bounds check.
C++
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function baz(): void {{ return 81; }}
function baz(): number {{ return 81; }}
Return type mismatch.
TypeScript
my @arr = (1,90,6);
my @arr = (1,90,6);
Correct.
Perl
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
values(8)
if length(values) >= 8, values(8), end
Check length.
MATLAB
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<person age=36>
<person age="36">
Quote attribute.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<note><desc>hello</desc><age>65</age></note
<note><desc>hello</desc><age>65</age></note>
Add closing >.
XML
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const count;
const count = 20;
Initialize const.
JavaScript
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
{{"age":"data" "age":80}}
{{"age":"data", "age":80}}
Add comma.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust