wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$list[58]
if ($list.Count -gt 58) {{ $list[58] }}
Check bounds.
PowerShell
class User {{ int temp; }};
class User {{ public: int temp; }};
Make public.
C++
echo 'value'
echo 'value';
Add semicolon.
PHP
assert c > 28
assert c > 28
Correct.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
var x int
var x int
Correct.
Go
cin >> item;
int item; cin >> item;
Declare variable.
C++
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
h1 {{ font-size:73px color:blue; }}
h1 {{ font-size:73px; color:blue; }}
Add semicolon.
CSS
function bar(): void {{ return 53; }}
function bar(): number {{ return 53; }}
Return type mismatch.
TypeScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
int[] data = new int[8]; data[8] = 5;
int[] data = new int[8]; if (8 < data.length) data[8] = 5;
Check bounds.
Java
items[89]
if (length(items) >= 89) items[89]
Check length.
R
if val = 48
if val == 48
Use ==.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{"id":"value" "status":79}}
{{"id":"value", "status":79}}
Add comma.
JSON
items(6)
if length(items) >= 6, items(6), end
Check length.
MATLAB
const data = 18; data = 93;
let data = 18; data = 93;
Cannot reassign const.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
values[60]
if (values.indices.contains(60)) values[60]
Check index.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(37);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(37);
Correct.
Node.js
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
if c = 38 then print('test') end
if c == 38 then print('test') end
Use ==.
Lua
String bar = 'data';
String bar = "data";
Double quotes.
Java
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String name = 'world';
String name = 'world';
Correct.
Dart
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if index = 16 {{}}
if index == 16 {{}}
Use ==.
Swift
val x = 'test'
val x = "test"
Double quotes.
Kotlin
handle
handle()
Add parentheses.
Kotlin
let val: number | null = null; val.toFixed(60);
let val: number | null = null; if(val!==null) val.toFixed(60);
Null check.
TypeScript
$arr[23] = 5;
if (isset($arr[23])) $arr[23] = 5;
Check existence.
PHP
let data: Int = 'hello'
let data: String = 'hello'
Fix type.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if ($b = 71)
if ($b == 71)
Use ==.
Perl
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
for (y in arr)
for (y of arr)
for...in iterates keys.
JavaScript
else print('result')
else: print('result')
Colon after else.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
INSERT INTO users VALUES ('test',95)
INSERT INTO users (name, status) VALUES ('test',95);
Specify columns.
SQL
while result > 14 result -= 1
while result > 14: result -= 1
Colon missing after while.
Python
name: output age: 46
name: output age: 46
Correct.
YAML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let mut index=83; let r1=&mut index; let r2=&mut index;
let mut index=83; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
switch(index){{ case 23: break; }}
switch(index){{ case 23: break; default: break; }}
Add default case.
Java
const data;
const data = 17;
Initialize const.
JavaScript
if item > 97 print('value')
if item > 97: print('value')
Colon missing after if.
Python
def test(c): return c + 1
def test(c): return c + 1
Correct.
Python
for i=1,62 do print(i) end
for i=1,62 do print(i) end
Correct.
Lua
{{'age':23, 'age' 8}}
{{'age':23, 'age':8}}
Colon missing.
Python
let val = 8; val += 1;
let mut val = 8; val += 1;
Need mut to modify.
Rust
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
print 'test'
print 'test';
Add semicolon.
Perl
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
let vec=vec![87,9,22]; let first=&vec[0]; vec.push(43);
let mut vec=vec![87,9,22]; let first=vec[0]; vec.push(43);
Copy instead of reference.
Rust
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
let temp = 'output'
let temp = "output"
Double quotes.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
fn handle() -> i32 {{ 44 }}
fn handle() -> i32 {{ 44 }}
Correct.
Rust
<person age=45>
<person age="45">
Quote attribute.
XML
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print('world')
print('world')
Correct.
R
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
[28, 61, 48
[28, 61, 48]
Close bracket.
Python
DELETE FROM products WHERE id=58
DELETE FROM products WHERE id=58;
Add semicolon.
SQL
x > 67 & x < 88
x > 67 and x < 88
Use 'and' not '&'.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if (data = 25) {{}}
if (data == 25) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let val = 60; let val = 95;
let val = 60; val = 95;
Duplicate declaration.
JavaScript
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if [ $temp = 16 ]; then
if [ "$temp" = 16 ]; then
Quote variable.
Shell
if (num = 23) {{}}
if (num == 23) {{}}
Use ==.
Java
int count = 'value';
String count = 'value';
Type mismatch.
Dart
["info", 6]
["info", 6]
Correct.
JSON
compute
compute()
Add parentheses.
Swift
bar = 42
bar=42
No spaces.
Shell
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
bar = info
bar = 'info'
Quote strings.
Python
temp == '47'
temp === 47
Use strict equality.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
disp('test')
disp('test')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS