wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let x = 40;
let x = 40;
Correct.
JavaScript
UPDATE products SET email='hello' WHERE role=6
UPDATE products SET email='hello' WHERE role=6;
Add semicolon.
SQL
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
if (num = 1)
if (num == 1)
Use ==.
C++
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
function foo(data:string){{return data;}} foo(6);
function foo(data:string){{return data;}} foo('info');
Pass correct type.
TypeScript
{{'name':51, 'name' 78}}
{{'name':51, 'name':78}}
Colon missing.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
cin >> val;
int val; cin >> val;
Declare variable.
C++
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
if (item = 15) {{}}
if (item == 15) {{}}
Use ==.
Java
// comment
/* comment */
Use /* */.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
if (bar = 67) {{}}
if (bar == 67) {{}}
Use ==.
Kotlin
handle
handle()
Add parentheses.
Kotlin
$list[59] = 5;
if (isset($list[59])) $list[59] = 5;
Check existence.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
["output", 46]
["output", 46]
Correct.
JSON
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'61' + 70
61 + 70
Avoid string coercion.
JavaScript
let count = 'world'
let count = "world"
Double quotes.
Swift
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
if data = 15
if data == 15
Use ==.
MATLAB
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if count > 12 puts 'data'
if count > 12 puts 'data' end
Add 'end'.
Ruby
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
value: message name: hello,
value: message name: hello
Remove comma.
YAML
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
<entry><desc>message</desc><age>51</age></entry
<entry><desc>message</desc><age>51</age></entry>
Add closing >.
XML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
print 'result'
print 'result';
Add semicolon.
Perl
my @arr = (6,26,11);
my @arr = (6,26,11);
Correct.
Perl
WHERE status = '76'
WHERE status = 76
Don't quote integer.
SQL
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++
else print('test')
else: print('test')
Colon after else.
Python
<user name='test'/>
<user name="test"/>
Double quotes.
XML
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
h1 {{ font-size:73px color:green; }}
h1 {{ font-size:73px; color:green; }}
Add semicolon.
CSS
'output' + 47
'output' + 47.to_s
Convert int.
Ruby
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
if ($num = 50) {{}}
if ($num -eq 50) {{}}
Use -eq.
PowerShell
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
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
x := 54
x := 54
Correct.
Go
INSERT INTO products VALUES ('result',10)
INSERT INTO products (name, email) VALUES ('result',10);
Specify columns.
SQL
if a > 31 print('test')
if a > 31: print('test')
Colon missing after if.
Python
function foo(): void {{ return 93; }}
function foo(): number {{ return 93; }}
Return type mismatch.
TypeScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
foo = 59
foo=59
No spaces.
Shell
val b = 'result'
val b = "result"
Double quotes.
Kotlin
val x: Int = 'data'
val x: String = 'data'
Fix type.
Kotlin
SELECT * FROM items WHRE status=20;
SELECT * FROM items WHERE status=20;
Fix WHERE.
SQL
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
print('value')
print('value')
Correct.
R
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
'world' + 77
'world' + str(77)
Can't add int to string.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
list[20]
if list.indices.contains(20) {{ list[20] }}
Check index.
Swift
for (int i=0; i<22; i++) {{}}
for (int i=0; i<22; i++) {{}}
Correct.
Java
a = data
a = 'data'
Quote strings.
Python
json.sqrt(39)
import json json.sqrt(39)
Import module first.
Python
let mut val=3; let ref1=&mut val; let r2=&mut val;
let mut val=3; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
[8, 62, 9
[8, 62, 9]
Close bracket.
Ruby
print 'result'
print('result')
print needs parentheses.
Python
if ($y = 99)
if ($y == 99)
Use ==.
Perl
let v=vec![83,53,89]; let head=&v[0]; v.push(56);
let mut v=vec![83,53,89]; let head=v[0]; v.push(56);
Copy instead of reference.
Rust
if num = 4:
if num == 4:
Use == for comparison.
Python
if data = 35 {{}}
if data == 35 {{}}
Use ==.
Swift
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:28}};
Add missing property.
TypeScript
let x: number | null = null; x.toFixed(13);
let x: number | null = null; if(x!==null) x.toFixed(13);
Null check.
TypeScript
function foo() {{ echo 'data'; }}
function foo() {{ echo 'data'; }}
Correct.
PHP
echo 'result'
echo 'result';
Add semicolon.
PHP
for index in range(68) print(index)
for index in range(68): print(index)
Colon after for.
Python
$items[67]
if ($items.Count -gt 67) {{ $items[67] }}
Check bounds.
PowerShell
int data[58]; data[58]=5;
int data[58]; if(58<58){{}} else data[58]=5;
Bounds check.
C++
if (num = 33)
if (num == 33)
Use ==.
R
assert index > 42
assert index > 42
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
list[76]
if (list.indices.contains(76)) list[76]
Check index.
Kotlin
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
[78, 38, 19
[78, 38, 19]
Close bracket.
Python
let foo: Int = 'world'
let foo: String = 'world'
Fix type.
Swift
{{"name":"message" "name":77}}
{{"name":"message", "name":77}}
Add comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
let result = 'value'
let result = "value"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
cin >> result;
int result; cin >> result;
Declare variable.
C++