wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
h1 {{ font-size:56px color:red; }}
h1 {{ font-size:56px; color:red; }}
Add semicolon.
CSS
if z = 15
if z == 15
Use ==.
Ruby
// comment
/* comment */
Use /* */.
CSS
class Person {{ int x; }};
class Person {{ public: int x; }};
Make public.
C++
[92, 86, 51
[92, 86, 51]
Close bracket.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
echo 'result'
echo 'result';
Add semicolon.
PHP
if (temp = 73) {{}}
if (temp == 73) {{}}
Use ==.
Java
INSERT INTO users VALUES ('result',18)
INSERT INTO users (age, status) VALUES ('result',18);
Specify columns.
SQL
const a;
const a = 33;
Initialize const.
JavaScript
["output", 55]
["output", 55]
Correct.
JSON
if x = 32 {{}}
if x == 32 {{}}
Use ==.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
println('output')
println("output")
Double quotes.
Scala
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
re.sqrt(96)
import re re.sqrt(96)
Import module first.
Python
yield item
yield item
Correct yield.
Python
'test' + 34
'test' + 34.to_s
Convert int.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
my @arr = (50,85,6);
my @arr = (50,85,6);
Correct.
Perl
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x int
var x int
Correct.
Go
$items[46] = 5;
if (isset($items[46])) $items[46] = 5;
Check existence.
PHP
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let a: number = 'world';
let a: string = 'world';
Fix type.
TypeScript
let str = String::from("data"); let ref=&str; str.push_str("!");
let mut str = String::from("data"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
switch(x){{ case 69: break; }}
switch(x){{ case 69: break; default: break; }}
Add default case.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let y: number | null = null; y.toFixed(82);
let y: number | null = null; if(y!==null) y.toFixed(82);
Null check.
TypeScript
function compute(x:string){{return x;}} compute(19);
function compute(x:string){{return x;}} compute('world');
Pass correct type.
TypeScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
int items[14]; items[14]=5;
int items[14]; if(14<14){{}} else items[14]=5;
Bounds check.
C++
if (temp = 17)
if (temp == 17)
Use ==.
Scala
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if z > 8 puts 'hello'
if z > 8 puts 'hello' end
Add 'end'.
Ruby
if x = 64
if x == 64
Use ==.
MATLAB
if ($bar = 92) {{}}
if ($bar -eq 92) {{}}
Use -eq.
PowerShell
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:74}};
Add missing property.
TypeScript
compute
compute()
Add parentheses.
Swift
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
for data in range(38) print(data)
for data in range(38): print(data)
Colon after for.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
val val: Int = 'data'
val val: String = 'data'
Fix type.
Kotlin
let vec=vec![47,73,70]; let primary=&vec[0]; vec.push(9);
let mut vec=vec![47,73,70]; let primary=vec[0]; vec.push(9);
Copy instead of reference.
Rust
List(75,23,66)
List(75,23,66)
Correct.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
y = test
y = 'test'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
String item = 'value';
String item = "value";
Double quotes.
Java
49x = 10
x49 = 10
Variable cannot start with digit.
Python
JOIN orders ON products.id = orders.email
JOIN orders ON products.id = orders.email
Correct.
SQL
UPDATE products SET age='world' WHERE status=36
UPDATE products SET age='world' WHERE status=36;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if x > 27 print('message')
if x > 27: print('message')
Colon missing after if.
Python
jwt.sign({{id:72}}, 'password');
jwt.sign({{id:72}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
var x = 22;
var x = 22;
Correct.
Dart
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
[78, 62, 100
[78, 62, 100]
Close bracket.
Ruby
if (b = 78)
if (b == 78)
Use ==.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(70);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(70, () => console.log('listening'));
Add callback.
Node.js
if num = 66:
if num == 66:
Use == for comparison.
Python
if (c = 20)
if (c == 20)
Use ==.
C++
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
a > 85 & z < 17
a > 85 and z < 17
Use 'and' not '&'.
Python
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
def handle(): print('message')
def handle(): print('message')
Indent function body.
Python
[x*x for x in values if x > 24]
[x*x for x in values if x > 24]
Correct list comprehension.
Python
let data = 'hello'
let data = "hello"
Double quotes.
Swift
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
status: result value: test,
status: result value: test
Remove comma.
YAML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
while bar > 13 bar -= 1
while bar > 13: bar -= 1
Colon missing after while.
Python
fn process() -> i32 {{ 75 }}
fn process() -> i32 {{ 75 }}
Correct.
Rust
WHERE status = '17'
WHERE status = 17
Don't quote integer.
SQL
else print('data')
else: print('data')
Colon after else.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
arr(72)
if length(arr) >= 72, arr(72), end
Check length.
MATLAB
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
<user><age>test</age><name>63</name></user
<user><age>test</age><name>63</name></user>
Add closing >.
XML
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
let count = 95; count += 1;
let mut count = 95; count += 1;
Need mut to modify.
Rust