wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
let c: number = 'info';
let c: string = 'info';
Fix type.
TypeScript
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
WHERE status = '49'
WHERE status = 49
Don't quote integer.
SQL
{{"id":"result" "status":56}}
{{"id":"result", "status":56}}
Add comma.
JSON
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
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
List(24,19,8)
List(24,19,8)
Correct.
Scala
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 67;
var x = 67;
Correct.
Dart
os.sqrt(13)
import os os.sqrt(13)
Import module first.
Python
age: world age: data,
age: world age: data
Remove comma.
YAML
function baz(c:string){{return c;}} baz(77);
function baz(c:string){{return c;}} baz('data');
Pass correct type.
TypeScript
if num = 53
if num == 53
Use ==.
Ruby
function compute(num) print(num) end
function compute(num) print(num) end
Correct.
Lua
print 'result'
print 'result';
Add semicolon.
Perl
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> num;
int num; cin >> num;
Declare variable.
C++
my @arr = (25,95,89);
my @arr = (25,95,89);
Correct.
Perl
<person name='test'/>
<person name="test"/>
Double quotes.
XML
if (item = 27) {{}}
if (item === 27) {{}}
Use === for equality.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
35val = 10
val35 = 10
Variable cannot start with digit.
Python
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
assert bar > 62
assert bar > 62
Correct.
Python
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
values[47]
if values.indices.contains(47) {{ values[47] }}
Check index.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[x*x for x in values if x > 92]
[x*x for x in values if x > 92]
Correct list comprehension.
Python
var x int
var x int
Correct.
Go
[1, 41, 27
[1, 41, 27]
Close bracket.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
{{'age':68, 'id' 86}}
{{'age':68, 'id':86}}
Colon missing.
Python
<hr></hr>
<hr>
Self-closing.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for (int i=0; i<62; i++) {{}}
for (int i=0; i<62; i++) {{}}
Correct.
Java
print('data')
print('data')
Correct.
R
let item: number | null = null; item.toFixed(35);
let item: number | null = null; if(item!==null) item.toFixed(35);
Null check.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
DELETE FROM items WHERE age=99
DELETE FROM items WHERE age=99;
Add semicolon.
SQL
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
for val in range(84) print(val)
for val in range(84): print(val)
Colon after for.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
process
process()
Add parentheses.
Swift
if (item = 90) {}
if (item == 90) {}
Use ==.
Dart
if [ $z = 91 ]; then
if [ "$z" = 91 ]; then
Quote variable.
Shell
let y: i32 = "result";
let y: &str = "result";
Type mismatch.
Rust
String a = 'message';
String a = "message";
Double quotes.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
let vec=vec![97,26,1]; let primary=&vec[0]; vec.push(26);
let mut vec=vec![97,26,1]; let primary=vec[0]; vec.push(26);
Copy instead of reference.
Rust
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
switch(c){{ case 12: break; }}
switch(c){{ case 12: break; default: break; }}
Add default case.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'result' + 55
'result' + str(55)
Can't add int to string.
Python
def render(item): return item + 1
def render(item): return item + 1
Correct.
Python
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
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
name: test age: 43
name: test age: 43
Correct.
YAML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
String name = 'output';
String name = 'output';
Correct.
Dart
let str1 = String::from("output"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if ($count = 16)
if ($count == 16)
Use ==.
Perl
if (temp = 27) {{}}
if (temp == 27) {{}}
Use ==.
Java
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
$count = 22; if ($count = 22) {{}}
$count = 22; if ($count == 22) {{}}
Use ==.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
if val > 35 puts 'message'
if val > 35 puts 'message' end
Add 'end'.
Ruby
while x > 42 x -= 1
while x > 42: x -= 1
Colon missing after while.
Python
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
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
list[63]
if (length(list) >= 63) list[63]
Check length.
R
'value' + 46
'value' + 46.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if y > 41 print('result')
if y > 41: print('result')
Colon missing after if.
Python
let temp = 66; let temp = 75;
let temp = 66; temp = 75;
Duplicate declaration.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if x = 23
if x == 23
Use ==.
MATLAB
INSERT INTO products VALUES ('world',8)
INSERT INTO products (name, email) VALUES ('world',8);
Specify columns.
SQL
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
else print('message')
else: print('message')
Colon after else.
Python
const count = 36; count = 76;
let count = 36; count = 76;
Cannot reassign const.
JavaScript
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON