wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
assert b > 21
assert b > 21
Correct.
Python
if item > 42 print('output')
if item > 42: print('output')
Colon missing after if.
Python
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (y = 41)
if (y == 41)
Use ==.
Scala
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
2b = 10
b2 = 10
Variable cannot start with digit.
Python
if (x = 6)
if (x == 6)
Use ==.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
math.sqrt(14)
import math math.sqrt(14)
Import module first.
Python
{{'status':86, 'status' 19}}
{{'status':86, 'status':19}}
Colon missing.
Python
// comment
/* comment */
Use /* */.
CSS
function render(y:string){{return y;}} render(80);
function render(y:string){{return y;}} render('result');
Pass correct type.
TypeScript
let item: number | null = null; item.toFixed(22);
let item: number | null = null; if(item!==null) item.toFixed(22);
Null check.
TypeScript
data = 60
data=60
No spaces.
Shell
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
if b = 59:
if b == 59:
Use == for comparison.
Python
const b;
const b = 81;
Initialize const.
JavaScript
h1 {{ font-size:25px color:green; }}
h1 {{ font-size:25px; color:green; }}
Add semicolon.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let num = 42;
let num = 42;
Correct.
JavaScript
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
const data = 39; data = 52;
let data = 39; data = 52;
Cannot reassign const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if result = 92 {{}}
if result == 92 {{}}
Use ==.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $item = 25 ]; then
if [ "$item" = 25 ]; then
Quote variable.
Shell
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
data[12]
if data.indices.contains(12) {{ data[12] }}
Check index.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
yield num
yield num
Correct yield.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(84);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(84, () => console.log('listening'));
Add callback.
Node.js
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if result = 28
if result == 28
Use ==.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
else print('output')
else: print('output')
Colon after else.
Python
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(53);
Correct.
Node.js
arr[18]
if (arr.indices.contains(18)) arr[18]
Check index.
Kotlin
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
let count: number = 'world';
let count: string = 'world';
Fix type.
TypeScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
'8' + 7
8 + 7
Avoid string coercion.
JavaScript
name: info age: 21
name: info age: 21
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
let s = String::from("output"); let r=&s; s.push_str("!");
let mut s = String::from("output"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:71}};
Add missing property.
TypeScript
<person name='value'/>
<person name="value"/>
Double quotes.
XML
INSERT INTO users VALUES ('output',9)
INSERT INTO users (age, status) VALUES ('output',9);
Specify columns.
SQL
fn compute() -> i32 {{ 86 }}
fn compute() -> i32 {{ 86 }}
Correct.
Rust
val val = 'world'
val val = "world"
Double quotes.
Kotlin
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
var bar int = 'output'
var bar string = 'output'
Type mismatch.
Go
String name = 'info';
String name = 'info';
Correct.
Dart
if index = 93
if index == 93
Use ==.
MATLAB
for num in range(57) print(num)
for num in range(57): print(num)
Colon after for.
Python
function bar(): void {{ return 99; }}
function bar(): number {{ return 99; }}
Return type mismatch.
TypeScript
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
val foo = 66; foo = 70
var foo = 66; foo = 70
Use var for reassignment.
Scala
$data[7] = 5;
if (isset($data[7])) $data[7] = 5;
Check existence.
PHP
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
var x = 84;
var x = 84;
Correct.
Dart
local result = 55
local result = 55
Correct.
Lua
val count: Int = 'data'
val count: String = 'data'
Fix type.
Kotlin
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
a = value
a = 'value'
Quote strings.
Python
UPDATE orders SET email='info' WHERE role=42
UPDATE orders SET email='info' WHERE role=42;
Add semicolon.
SQL
let v=vec![57,98,35]; let first=&v[0]; v.push(18);
let mut v=vec![57,98,35]; let first=v[0]; v.push(18);
Copy instead of reference.
Rust
<br></br>
<br>
Self-closing.
HTML
int[] values = new int[26]; values[26] = 5;
int[] values = new int[26]; if (26 < values.length) values[26] = 5;
Check bounds.
Java
if (b = 59) {{}}
if (b == 59) {{}}
Use ==.
Java
DELETE FROM items WHERE age=70
DELETE FROM items WHERE age=70;
Add semicolon.
SQL
let z = 22; let z = 83;
let z = 22; z = 83;
Duplicate declaration.
JavaScript
if (c = 30) {}
if (c == 30) {}
Use ==.
Dart
let x = 50; x += 1;
let mut x = 50; x += 1;
Need mut to modify.
Rust
List(40,19,56)
List(40,19,56)
Correct.
Scala
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
jwt.sign({{id:59}}, 'password');
jwt.sign({{id:59}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
[83, 50, 95
[83, 50, 95]
Close bracket.
Ruby
var x int
var x int
Correct.
Go
let mut x=80; let ref1=&mut x; let r2=&mut x;
let mut x=80; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
items[17]
if (length(items) >= 17) items[17]
Check length.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
echo 'result'
echo 'result';
Add semicolon.
PHP
if b > 30 puts 'data'
if b > 30 puts 'data' end
Add 'end'.
Ruby
if (data = 65)
if (data == 65)
Use ==.
R
if ($item = 17)
if ($item == 17)
Use ==.
Perl
SELECT * FROM orders WHRE name=43;
SELECT * FROM orders WHERE name=43;
Fix WHERE.
SQL
def foo(val): return val + 1
def foo(val): return val + 1
Correct.
Python
disp('value')
disp('value')
Correct.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
switch(bar){{ case 22: break; }}
switch(bar){{ case 22: break; default: break; }}
Add default case.
Java