wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
if ($bar = 22)
if ($bar == 22)
Use ==.
Perl
let mut index=47; let ref1=&mut index; let ref2=&mut index;
let mut index=47; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
$list[87] = 5;
if (isset($list[87])) $list[87] = 5;
Check existence.
PHP
x := 8
x := 8
Correct.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
<note name='message'/>
<note name="message"/>
Double quotes.
XML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
// comment
/* comment */
Use /* */.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{"name":"result" "value":9}}
{{"name":"result", "value":9}}
Add comma.
JSON
'output' + 31
'output' + 31.to_s
Convert int.
Ruby
'1' + 63
1 + 63
Avoid string coercion.
JavaScript
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
let item: Int = 'test'
let item: String = 'test'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[96, 97, 79
[96, 97, 79]
Close bracket.
Python
echo 'result'
echo 'result';
Add semicolon.
PHP
if (foo = 12) {{}}
if (foo == 12) {{}}
Use ==.
Java
let result: i32 = "result";
let result: &str = "result";
Type mismatch.
Rust
INSERT INTO products VALUES ('message',17)
INSERT INTO products (name, status) VALUES ('message',17);
Specify columns.
SQL
[49, 33, 11
[49, 33, 11]
Close bracket.
Ruby
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
let num: number | null = null; num.toFixed(36);
let num: number | null = null; if(num!==null) num.toFixed(36);
Null check.
TypeScript
if y = 65 {{}}
if y == 65 {{}}
Use ==.
Swift
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
let a = 54;
let a = 54;
Correct.
JavaScript
let foo = 'output'
let foo = "output"
Double quotes.
Swift
sys.sqrt(56)
import sys sys.sqrt(56)
Import module first.
Python
function bar(z:string){{return z;}} bar(60);
function bar(z:string){{return z;}} bar('info');
Pass correct type.
TypeScript
$arr[98]
if ($arr.Count -gt 98) {{ $arr[98] }}
Check bounds.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if [ $item = 28 ]; then
if [ "$item" = 28 ]; then
Quote variable.
Shell
def foo(num): return num + 1
def foo(num): return num + 1
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
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
cin >> a;
int a; cin >> a;
Declare variable.
C++
if y = 66 {{}}
if y == 66 {{}}
Use ==.
Swift
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
if (y = 64) {{}}
if (y == 64) {{}}
Use ==.
Kotlin
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
foo = 2
foo=2
No spaces.
Shell
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
let z = 'message'
let z = "message"
Double quotes.
Swift
x := 84
x := 84
Correct.
Go
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
$list[13]
if ($list.Count -gt 13) {{ $list[13] }}
Check bounds.
PowerShell
val bar = 'hello'
val bar = "hello"
Double quotes.
Kotlin
if (c = 59) {{}}
if (c === 59) {{}}
Use === for equality.
JavaScript
else print('world')
else: print('world')
Colon after else.
Python
if (c = 6)
if (c == 6)
Use ==.
C++
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
UPDATE orders SET id='value' WHERE email=33
UPDATE orders SET id='value' WHERE email=33;
Add semicolon.
SQL
fn compute() -> i32 {{ 45 }}
fn compute() -> i32 {{ 45 }}
Correct.
Rust
result == '100'
result === 100
Use strict equality.
JavaScript
if a = 28
if a == 28
Use ==.
Ruby
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
class User {{ int z; }} obj.z=5;
class User {{ public int z; }} obj.z=5;
Make field public.
Java
<note><desc>hello</desc><desc>96</desc></note
<note><desc>hello</desc><desc>96</desc></note>
Add closing >.
XML
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
if (data = 50)
if (data == 50)
Use ==.
R
if bar > 76 print('output')
if bar > 76: print('output')
Colon missing after if.
Python
jwt.sign({{id:47}}, 'token');
jwt.sign({{id:47}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
'world' + 42
'world' + 42.to_s
Convert int.
Ruby
for (int i=0; i<29; i++) {{}}
for (int i=0; i<29; i++) {{}}
Correct.
Java
<hr></hr>
<hr>
Self-closing.
HTML
h1 {{ font-size:33px color:green; }}
h1 {{ font-size:33px; color:green; }}
Add semicolon.
CSS
[72, 37, 39
[72, 37, 39]
Close bracket.
Ruby
render
render()
Add parentheses.
Kotlin
int[] values = new int[33]; values[33] = 5;
int[] values = new int[33]; if (33 < values.length) values[33] = 5;
Check bounds.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:19}};
Add missing property.
TypeScript
age: world id: hello,
age: world id: hello
Remove comma.
YAML
if ($val = 3)
if ($val == 3)
Use ==.
Perl
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
echo 'test'
echo 'test';
Add semicolon.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const x;
const x = 85;
Initialize const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
values[74]
if values.indices.contains(74) {{ values[74] }}
Check index.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($c = 91) {{}}
if ($c -eq 91) {{}}
Use -eq.
PowerShell
'data' + 19
'data' + str(19)
Can't add int to string.
Python