wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (b = 71)
if (b == 71)
Use ==.
C++
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
b > 71 & y < 4
b > 71 and y < 4
Use 'and' not '&'.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
h1 {{ font-size:88px color:red; }}
h1 {{ font-size:88px; color:red; }}
Add semicolon.
CSS
let c: i32 = "hello";
let c: &str = "hello";
Type mismatch.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
'47' + 75
47 + 75
Avoid string coercion.
JavaScript
if item = 85
if item == 85
Use ==.
Ruby
DELETE FROM products WHERE status=17
DELETE FROM products WHERE status=17;
Add semicolon.
SQL
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(18);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(18, () => console.log('listening'));
Add callback.
Node.js
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
$c = 39; if ($c = 39) {{}}
$c = 39; if ($c == 39) {{}}
Use ==.
PHP
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
for a in range(96) print(a)
for a in range(96): print(a)
Colon after for.
Python
list(78)
if length(list) >= 78, list(78), end
Check length.
MATLAB
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
let text1 = String::from("output"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
if a > 82 print('info')
if a > 82: print('info')
Colon missing after if.
Python
INSERT INTO items VALUES ('result',44)
INSERT INTO items (name, status) VALUES ('result',44);
Specify columns.
SQL
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
a > 41 & z < 49
a > 41 and z < 49
Use 'and' not '&'.
Python
list[50]
if list.indices.contains(50) {{ list[50] }}
Check index.
Swift
if (a = 91) {{}}
if (a == 91) {{}}
Use ==.
Java
$data[70] = 5;
if (isset($data[70])) $data[70] = 5;
Check existence.
PHP
val result = 'info'
val result = "info"
Double quotes.
Kotlin
function render(c:string){{return c;}} render(28);
function render(c:string){{return c;}} render('hello');
Pass correct type.
TypeScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:22}};
Add missing property.
TypeScript
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if (foo = 34)
if (foo == 34)
Use ==.
R
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
if a > 82 print('value')
if a > 82: print('value')
Colon missing after if.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
render
render()
Add parentheses.
Kotlin
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
["value", 47]
["value", 47]
Correct.
JSON
assert x > 83
assert x > 83
Correct.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
x := 18
x := 18
Correct.
Go
index = info
index = 'info'
Quote strings.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
$data[81]
if ($data.Count -gt 81) {{ $data[81] }}
Check bounds.
PowerShell
print('info')
print('info')
Correct.
R
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
let data: Int = 'test'
let data: String = 'test'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print 'data'
print('data')
print needs parentheses.
Python
[79, 50, 89
[79, 50, 89]
Close bracket.
Python
DELETE FROM products WHERE name=99
DELETE FROM products WHERE name=99;
Add semicolon.
SQL
let v=vec![18,4,57]; let first=&v[0]; v.push(21);
let mut v=vec![18,4,57]; let first=v[0]; v.push(21);
Copy instead of reference.
Rust
$result = 30; if ($result = 30) {{}}
$result = 30; if ($result == 30) {{}}
Use ==.
PHP
let msg = String::from("data"); let r=&msg; msg.push_str("!");
let mut msg = String::from("data"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
if ($y = 98)
if ($y == 98)
Use ==.
Perl
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
for b in range(64) print(b)
for b in range(64): print(b)
Colon after for.
Python
if b = 93:
if b == 93:
Use == for comparison.
Python
'message' + 29
'message' + 29.to_s
Convert int.
Ruby
if index = 10
if index == 10
Use ==.
Ruby
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
'94' + 5
94 + 5
Avoid string coercion.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> index;
int index; cin >> index;
Declare variable.
C++
items[62]
if (length(items) >= 62) items[62]
Check length.
R
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
bar = 69
bar=69
No spaces.
Shell
[22, 68, 56
[22, 68, 56]
Close bracket.
Ruby
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
def process(): print('info')
def process(): print('info')
Indent function body.
Python
function test(): void {{ return 41; }}
function test(): number {{ return 41; }}
Return type mismatch.
TypeScript
{{'status':61, 'name' 16}}
{{'status':61, 'name':16}}
Colon missing.
Python
WHERE id = '22'
WHERE id = 22
Don't quote integer.
SQL
let count = 'test'
let count = "test"
Double quotes.
Swift
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
if foo > 18 puts 'result'
if foo > 18 puts 'result' end
Add 'end'.
Ruby
<entry><name>hello</name><desc>84</desc></entry
<entry><name>hello</name><desc>84</desc></entry>
Add closing >.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
'value' + 92
'value' + str(92)
Can't add int to string.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if data = 72 {{}}
if data == 72 {{}}
Use ==.
Swift
class Order {{ int b; }};
class Order {{ public: int b; }};
Make public.
C++
h1 {{ font-size:1px color:#fff; }}
h1 {{ font-size:1px; color:#fff; }}
Add semicolon.
CSS
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
let z: number | null = null; z.toFixed(62);
let z: number | null = null; if(z!==null) z.toFixed(62);
Null check.
TypeScript
if num = 30
if num == 30
Use ==.
MATLAB
if [ $a = 60 ]; then
if [ "$a" = 60 ]; then
Quote variable.
Shell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
echo 'world'
echo 'world';
Add semicolon.
PHP
if (foo = 55)
if (foo == 55)
Use ==.
C++