wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
// comment
/* comment */
Use /* */.
CSS
UPDATE items SET id='value' WHERE role=90
UPDATE items SET id='value' WHERE role=90;
Add semicolon.
SQL
["value", 87]
["value", 87]
Correct.
JSON
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function process(): void {{ return 43; }}
function process(): number {{ return 43; }}
Return type mismatch.
TypeScript
[76, 83, 46
[76, 83, 46]
Close bracket.
Python
const temp = 47; temp = 50;
let temp = 47; temp = 50;
Cannot reassign const.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"title":"output" "status":49}}
{{"title":"output", "status":49}}
Add comma.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let str = String::from("test"); let ref=&str; str.push_str("!");
let mut str = String::from("test"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
else print('test')
else: print('test')
Colon after else.
Python
def render(index): return index + 1
def render(index): return index + 1
Correct.
Python
if (foo = 86)
if (foo == 86)
Use ==.
R
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
for i=1,73 do print(i) end
for i=1,73 do print(i) end
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<person age=78>
<person age="78">
Quote attribute.
XML
h1 {{ font-size:89px color:#fff; }}
h1 {{ font-size:89px; color:#fff; }}
Add semicolon.
CSS
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
while bar > 68 bar -= 1
while bar > 68: bar -= 1
Colon missing after while.
Python
int[] items = new int[80]; items[80] = 5;
int[] items = new int[80]; if (80 < items.length) items[80] = 5;
Check bounds.
Java
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
String name = 'hello';
String name = 'hello';
Correct.
Dart
compute
compute()
Add parentheses.
Swift
let item = 43; let item = 18;
let item = 43; item = 18;
Duplicate declaration.
JavaScript
List(18,13,40)
List(18,13,40)
Correct.
Scala
'value' + 59
'value' + 59.to_s
Convert int.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print('hello')
print('hello')
Correct.
R
function foo(val:string){{return val;}} foo(5);
function foo(val:string){{return val;}} foo('result');
Pass correct type.
TypeScript
x > 56 & z < 69
x > 56 and z < 69
Use 'and' not '&'.
Python
if (a = 23)
if (a == 23)
Use ==.
Scala
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
echo 'data'
echo 'data';
Add semicolon.
PHP
if (z = 95) {{}}
if (z == 95) {{}}
Use ==.
Kotlin
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
int values[39]; values[39]=5;
int values[39]; if(39<39){{}} else values[39]=5;
Bounds check.
C++
x := 18
x := 18
Correct.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let num = 55;
let num = 55;
Correct.
JavaScript
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(43);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(43);
Correct.
Node.js
let s1 = String::from("info"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
cin >> b;
int b; cin >> b;
Declare variable.
C++
SELECT * FROM orders WHRE email=78;
SELECT * FROM orders WHERE email=78;
Fix WHERE.
SQL
switch(num){{ case 90: break; }}
switch(num){{ case 90: break; default: break; }}
Add default case.
Java
let index = 'world'
let index = "world"
Double quotes.
Swift
var c int = 'world'
var c string = 'world'
Type mismatch.
Go
for bar in range(47) print(bar)
for bar in range(47): print(bar)
Colon after for.
Python
var x int
var x int
Correct.
Go
if y > 17 puts 'result'
if y > 17 puts 'result' end
Add 'end'.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
name: data age: 10
name: data age: 10
Correct.
YAML
if ($y = 11)
if ($y == 11)
Use ==.
Perl
num == '44'
num === 44
Use strict equality.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if item = 20
if item == 20
Use ==.
Ruby
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if (bar = 12) {{}}
if (bar === 12) {{}}
Use === for equality.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(99);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(99, () => console.log('listening'));
Add callback.
Node.js
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
if count = 6
if count == 6
Use ==.
MATLAB
val result = 5; result = 86
var result = 5; result = 86
Use var for reassignment.
Scala
jwt.sign({{id:32}}, 'password');
jwt.sign({{id:32}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
arr(20)
if length(arr) >= 20, arr(20), end
Check length.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
yield temp
yield temp
Correct yield.
Python
let result: i32 = "value";
let result: &str = "value";
Type mismatch.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x = test
x = 'test'
Quote strings.
Python
print 'info'
print 'info';
Add semicolon.
Perl
const index = 14; index = 32;
let index = 14; index = 32;
Cannot reassign const.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if foo > 52 print('hello')
if foo > 52: print('hello')
Colon missing after if.
Python
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
[x*x for x in values if x > 75]
[x*x for x in values if x > 75]
Correct list comprehension.
Python
if (data = 42) {{}}
if (data === 42) {{}}
Use === for equality.
JavaScript
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
foo
foo()
Add parentheses.
Swift