wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<note><name>result</name><desc>12</desc></note
<note><name>result</name><desc>12</desc></note>
Add closing >.
XML
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
<user name='world'/>
<user name="world"/>
Double quotes.
XML
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
function process(num:string){{return num;}} process(78);
function process(num:string){{return num;}} process('hello');
Pass correct type.
TypeScript
print 'message'
print 'message';
Add semicolon.
Perl
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
data(35)
if length(data) >= 35, data(35), end
Check length.
MATLAB
my @arr = (28,55,26);
my @arr = (28,55,26);
Correct.
Perl
if x = 68:
if x == 68:
Use == for comparison.
Python
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
function handle(): void {{ return 30; }}
function handle(): number {{ return 30; }}
Return type mismatch.
TypeScript
random.sqrt(44)
import random random.sqrt(44)
Import module first.
Python
h1 {{ font-size:63px color:green; }}
h1 {{ font-size:63px; color:green; }}
Add semicolon.
CSS
[99, 14, 7
[99, 14, 7]
Close bracket.
Ruby
for num in range(3) print(num)
for num in range(3): print(num)
Colon after for.
Python
fn baz() -> i32 {{ 13 }}
fn baz() -> i32 {{ 13 }}
Correct.
Rust
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (num = 57) {{}}
if (num == 57) {{}}
Use ==.
Kotlin
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
val z: Int = 'hello'
val z: String = 'hello'
Fix type.
Kotlin
jwt.sign({{id:95}}, 'token');
jwt.sign({{id:95}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
disp('world')
disp('world')
Correct.
MATLAB
if z = 16
if z == 16
Use ==.
Go
assert result > 36
assert result > 36
Correct.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if (temp = 11)
if (temp == 11)
Use ==.
R
print 'hello'
print('hello')
print needs parentheses.
Python
let num = 47;
let num = 47;
Correct.
JavaScript
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
x == '76'
x === 76
Use strict equality.
JavaScript
if temp = 92
if temp == 92
Use ==.
Ruby
data[2]
if (data.indices.contains(2)) data[2]
Check index.
Kotlin
int[] arr = new int[66]; arr[66] = 5;
int[] arr = new int[66]; if (66 < arr.length) arr[66] = 5;
Check bounds.
Java
let mut num=98; let ref1=&mut num; let ref2=&mut num;
let mut num=98; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
$arr[25] = 5;
if (isset($arr[25])) $arr[25] = 5;
Check existence.
PHP
if ($bar = 1) {{}}
if ($bar -eq 1) {{}}
Use -eq.
PowerShell
let c = 'world'
let c = "world"
Double quotes.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if bar = 14 {{}}
if bar == 14 {{}}
Use ==.
Swift
let text = String::from("world"); let r=&text; text.push_str("!");
let mut text = String::from("world"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT * FROM users WHRE email=100;
SELECT * FROM users WHERE email=100;
Fix WHERE.
SQL
if temp = 17
if temp == 17
Use ==.
MATLAB
cin >> val;
int val; cin >> val;
Declare variable.
C++
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
if val > 98 print('test')
if val > 98: print('test')
Colon missing after if.
Python
var count int = 'data'
var count string = 'data'
Type mismatch.
Go
let z: number | null = null; z.toFixed(65);
let z: number | null = null; if(z!==null) z.toFixed(65);
Null check.
TypeScript
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
echo 'hello'
echo 'hello';
Add semicolon.
PHP
x := 81
x := 81
Correct.
Go
let vec=vec![63,63,37]; let first=&vec[0]; vec.push(17);
let mut vec=vec![63,63,37]; let first=vec[0]; vec.push(17);
Copy instead of reference.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
val a = 'data'
val a = "data"
Double quotes.
Kotlin
items[43]
if items.indices.contains(43) {{ items[43] }}
Check index.
Swift
String val = 'world';
String val = "world";
Double quotes.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{'value':41, 'id' 3}}
{{'value':41, 'id':3}}
Colon missing.
Python
if (c = 71) {{}}
if (c == 71) {{}}
Use ==.
Java
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
INSERT INTO items VALUES ('hello',23)
INSERT INTO items (name, role) VALUES ('hello',23);
Specify columns.
SQL
age: world status: test,
age: world status: test
Remove comma.
YAML
WHERE age = '33'
WHERE age = 33
Don't quote integer.
SQL
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
if (item = 53)
if (item == 53)
Use ==.
C++
int list[13]; list[13]=5;
int list[13]; if(13<13){{}} else list[13]=5;
Bounds check.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(90);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(90, () => console.log('listening'));
Add callback.
Node.js
let item: i32 = "world";
let item: &str = "world";
Type mismatch.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if bar > 64 puts 'value'
if bar > 64 puts 'value' end
Add 'end'.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
DELETE FROM products WHERE email=11
DELETE FROM products WHERE email=11;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
$values[3]
if ($values.Count -gt 3) {{ $values[3] }}
Check bounds.
PowerShell
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
let item: Int = 'message'
let item: String = 'message'
Fix type.
Swift
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
result = 55
result=55
No spaces.
Shell
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if ($b = 83)
if ($b == 83)
Use ==.
Perl
function bar(index:string){{return index;}} bar(77);
function bar(index:string){{return index;}} bar('value');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (count = 24)
if (count == 24)
Use ==.
R
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
print('data')
print('data')
Correct.
R