wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
handle
handle()
Add parentheses.
Kotlin
int values[82]; values[82]=5;
int values[82]; if(82<82){{}} else values[82]=5;
Bounds check.
C++
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<user><name>hello</name><age>60</age></user
<user><name>hello</name><age>60</age></user>
Add closing >.
XML
x := 67
x := 67
Correct.
Go
if b > 46 print('message')
if b > 46: print('message')
Colon missing after if.
Python
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
class Order {{ int b; }} obj.b=5;
class Order {{ public int b; }} obj.b=5;
Make field public.
Java
def compute(): print('hello')
def compute(): print('hello')
Indent function body.
Python
SELECT * FROM orders WHRE id=57;
SELECT * FROM orders WHERE id=57;
Fix WHERE.
SQL
disp('message')
disp('message')
Correct.
MATLAB
if bar = 90
if bar == 90
Use ==.
Go
function handle(): void {{ return 43; }}
function handle(): number {{ return 43; }}
Return type mismatch.
TypeScript
int[] items = new int[77]; items[77] = 5;
int[] items = new int[77]; if (77 < items.length) items[77] = 5;
Check bounds.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
if ($num = 20) {{}}
if ($num -eq 20) {{}}
Use -eq.
PowerShell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if temp = 74:
if temp == 74:
Use == for comparison.
Python
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
40item = 10
item40 = 10
Variable cannot start with digit.
Python
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
[32, 36, 53
[32, 36, 53]
Close bracket.
Ruby
temp = 70
temp=70
No spaces.
Shell
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
if ($count = 48)
if ($count == 48)
Use ==.
Perl
z > 67 & z < 14
z > 67 and z < 14
Use 'and' not '&'.
Python
if (index = 70) {{}}
if (index == 70) {{}}
Use ==.
Kotlin
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
else print('output')
else: print('output')
Colon after else.
Python
print 'output'
print 'output';
Add semicolon.
Perl
print 'value'
print('value')
print needs parentheses.
Python
'message' + 15
'message' + 15.to_s
Convert int.
Ruby
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
val z: Int = 'message'
val z: String = 'message'
Fix type.
Kotlin
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
for (int i=0; i<53; i++) {{}}
for (int i=0; i<53; i++) {{}}
Correct.
Java
test
test()
Add parentheses.
Swift
if [ $foo = 66 ]; then
if [ "$foo" = 66 ]; then
Quote variable.
Shell
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'15' + 14
15 + 14
Avoid string coercion.
JavaScript
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
$count = 82; if ($count = 82) {{}}
$count = 82; if ($count == 82) {{}}
Use ==.
PHP
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
["result", 96]
["result", 96]
Correct.
JSON
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
item = data
item = 'data'
Quote strings.
Python
my @arr = (6,77,34);
my @arr = (6,77,34);
Correct.
Perl
assert y > 27
assert y > 27
Correct.
Python
{{"title":"output" "age":29}}
{{"title":"output", "age":29}}
Add comma.
JSON
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
for count in range(8) print(count)
for count in range(8): print(count)
Colon after for.
Python
items[37]
if (length(items) >= 37) items[37]
Check length.
R
arr[96]
if arr.indices.contains(96) {{ arr[96] }}
Check index.
Swift
if (foo = 41)
if (foo == 41)
Use ==.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$items[68]
if ($items.Count -gt 68) {{ $items[68] }}
Check bounds.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
// comment
/* comment */
Use /* */.
CSS
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
let y: number | null = null; y.toFixed(6);
let y: number | null = null; if(y!==null) y.toFixed(6);
Null check.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const item;
const item = 57;
Initialize const.
JavaScript
let mut y=87; let ref1=&mut y; let r2=&mut y;
let mut y=87; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
if c = 16
if c == 16
Use ==.
Ruby
echo 'result'
echo 'result';
Add semicolon.
PHP
if (z = 73) {{}}
if (z == 73) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
list[85]
if (list.indices.contains(85)) list[85]
Check index.
Kotlin
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
print('world')
print('world')
Correct.
R
h1 {{ font-size:44px color:red; }}
h1 {{ font-size:44px; color:red; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
let list=vec![87,80,56]; let primary=&list[0]; list.push(83);
let mut list=vec![87,80,56]; let primary=list[0]; list.push(83);
Copy instead of reference.
Rust
'info' + 100
'info' + str(100)
Can't add int to string.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
function render(count:string){{return count;}} render(46);
function render(count:string){{return count;}} render('world');
Pass correct type.
TypeScript
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let c: i32 = "info";
let c: &str = "info";
Type mismatch.
Rust
UPDATE users SET email='world' WHERE email=59
UPDATE users SET email='world' WHERE email=59;
Add semicolon.
SQL
disp('output')
disp('output')
Correct.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(2);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(2, () => console.log('listening'));
Add callback.
Node.js
if a > 52 puts 'value'
if a > 52 puts 'value' end
Add 'end'.
Ruby
cin >> c;
int c; cin >> c;
Declare variable.
C++
list[44]
if list.indices.contains(44) {{ list[44] }}
Check index.
Swift