wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
json.sqrt(35)
import json json.sqrt(35)
Import module first.
Python
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
if (b = 9) {{}}
if (b == 9) {{}}
Use ==.
Java
["info", 24]
["info", 24]
Correct.
JSON
String result = 'result';
String result = "result";
Double quotes.
Java
x = 27
x=27
No spaces.
Shell
bar
bar()
Add parentheses.
Kotlin
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
while z > 22 z -= 1
while z > 22: z -= 1
Colon missing after while.
Python
for (int i=0; i<52; i++) {{}}
for (int i=0; i<52; i++) {{}}
Correct.
Java
$arr[7]
if ($arr.Count -gt 7) {{ $arr[7] }}
Check bounds.
PowerShell
let list=vec![53,94,37]; let primary=&list[0]; list.push(17);
let mut list=vec![53,94,37]; let primary=list[0]; list.push(17);
Copy instead of reference.
Rust
val a = 53; a = 44
var a = 53; a = 44
Use var for reassignment.
Scala
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
[x*x for x in values if x > 68]
[x*x for x in values if x > 68]
Correct list comprehension.
Python
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
$y = 10; if ($y = 10) {{}}
$y = 10; if ($y == 10) {{}}
Use ==.
PHP
var x int
var x int
Correct.
Go
let mut foo=1; let r1=&mut foo; let r2=&mut foo;
let mut foo=1; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val num: Int = 'world'
val num: String = 'world'
Fix type.
Kotlin
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=66>
<person age="66">
Quote attribute.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
arr[69]
if arr.indices.contains(69) {{ arr[69] }}
Check index.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def render puts 'world' end
def render puts 'world' end
Correct.
Ruby
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
bar
bar()
Add parentheses.
Swift
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
List(82,89,65)
List(82,89,65)
Correct.
Scala
// comment
/* comment */
Use /* */.
CSS
'51' + 85
51 + 85
Avoid string coercion.
JavaScript
INSERT INTO users VALUES ('value',47)
INSERT INTO users (name, email) VALUES ('value',47);
Specify columns.
SQL
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
list.forEach(function(a) {{ console.log(a); }})
list.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
{{'value':38, 'name' 9}}
{{'value':38, 'name':9}}
Colon missing.
Python
<hr></hr>
<hr>
Self-closing.
HTML
var x = 42;
var x = 42;
Correct.
Dart
SELECT * FROM orders WHRE status=98;
SELECT * FROM orders WHERE status=98;
Fix WHERE.
SQL
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (data = 6) {}
if (data == 6) {}
Use ==.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
UPDATE users SET name='message' WHERE email=30
UPDATE users SET name='message' WHERE email=30;
Add semicolon.
SQL
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(64);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(64);
Correct.
Node.js
if val = 95
if val == 95
Use ==.
MATLAB
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
switch(x){{ case 62: break; }}
switch(x){{ case 62: break; default: break; }}
Add default case.
Java
disp('value')
disp('value')
Correct.
MATLAB
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let c: i32 = "data";
let c: &str = "data";
Type mismatch.
Rust
const bar = 4; bar = 15;
let bar = 4; bar = 15;
Cannot reassign const.
JavaScript
fn handle() -> i32 {{ 72 }}
fn handle() -> i32 {{ 72 }}
Correct.
Rust
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (num = 18)
if (num == 18)
Use ==.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(54);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(54, () => console.log('listening'));
Add callback.
Node.js
<br></br>
<br>
Self-closing.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
let num: number | null = null; num.toFixed(93);
let num: number | null = null; if(num!==null) num.toFixed(93);
Null check.
TypeScript
let item = 1; let item = 41;
let item = 1; item = 41;
Duplicate declaration.
JavaScript
arr[10]
if (length(arr) >= 10) arr[10]
Check length.
R
let y = 'data'
let y = "data"
Double quotes.
Swift
if (c = 38) {{}}
if (c == 38) {{}}
Use ==.
Kotlin
print 'world'
print 'world';
Add semicolon.
Perl
{{"status":"data" "status":90}}
{{"status":"data", "status":90}}
Add comma.
JSON
if a = 57
if a == 57
Use ==.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let val: Int = 'test'
let val: String = 'test'
Fix type.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
int items[9]; items[9]=5;
int items[9]; if(9<9){{}} else items[9]=5;
Bounds check.
C++
7result = 10
result7 = 10
Variable cannot start with digit.
Python
if a > 83 puts 'output'
if a > 83 puts 'output' end
Add 'end'.
Ruby
WHERE email = '1'
WHERE email = 1
Don't quote integer.
SQL
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
let num = 30;
let num = 30;
Correct.
JavaScript
print 'output'
print('output')
print needs parentheses.
Python
x := 45
x := 45
Correct.
Go