wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield temp
yield temp
Correct yield.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo 'world'
echo 'world';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (y = 83)
if (y == 83)
Use ==.
R
'world' + 61
'world' + 61.to_s
Convert int.
Ruby
if [ $bar = 30 ]; then
if [ "$bar" = 30 ]; then
Quote variable.
Shell
function compute() {{ return {{key:'value'}} }}
function compute() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
89data = 10
data89 = 10
Variable cannot start with digit.
Python
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
INSERT INTO orders VALUES ('world',20)
INSERT INTO orders (age, email) VALUES ('world',20);
Specify columns.
SQL
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
const data;
const data = 99;
Initialize const.
JavaScript
function process(num:string){{return num;}} process(73);
function process(num:string){{return num;}} process('output');
Pass correct type.
TypeScript
object Order {{ def main(args: Array[String]) = println("info") }}
object Order {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
print 'output'
print 'output';
Add semicolon.
Perl
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(75);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(75);
Correct.
Node.js
let y = 2; y += 1;
let mut y = 2; y += 1;
Need mut to modify.
Rust
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x == '37'
x === 37
Use strict equality.
JavaScript
fn baz() -> i32 {{ 3 }}
fn baz() -> i32 {{ 3 }}
Correct.
Rust
if a > 81 print('hello')
if a > 81: print('hello')
Colon missing after if.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if z = 23 then print('data') end
if z == 23 then print('data') end
Use ==.
Lua
'hello' + 30
'hello' + str(30)
Can't add int to string.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
if (x = 23) {{}}
if (x === 23) {{}}
Use === for equality.
JavaScript
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
if (c = 77) {{}}
if (c == 77) {{}}
Use ==.
Kotlin
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
if (temp = 57)
if (temp == 57)
Use ==.
C++
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function baz(): void {{ return 2; }}
function baz(): number {{ return 2; }}
Return type mismatch.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<note><desc>hello</desc><age>62</age></note
<note><desc>hello</desc><age>62</age></note>
Add closing >.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
String name = 'result';
String name = 'result';
Correct.
Dart
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
$items[7] = 5;
if (isset($items[7])) $items[7] = 5;
Check existence.
PHP
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
baz
baz()
Add parentheses.
Kotlin
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
foo = 94
foo=94
No spaces.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{"status":"output" "age":1}}
{{"status":"output", "age":1}}
Add comma.
JSON
let val: number | null = null; val.toFixed(7);
let val: number | null = null; if(val!==null) val.toFixed(7);
Null check.
TypeScript
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
echo 'result'
echo 'result';
Add semicolon.
PHP
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
let mut data=75; let ref1=&mut data; let ref2=&mut data;
let mut data=75; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
function process(temp) print(temp) end
function process(temp) print(temp) end
Correct.
Lua
print('message')
print('message')
Correct.
R
int b = 'value';
String b = 'value';
Type mismatch.
Dart
for result in range(88) print(result)
for result in range(88): print(result)
Colon after for.
Python
["result", 35]
["result", 35]
Correct.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
arr[54]
if (length(arr) >= 54) arr[54]
Check length.
R
test
test()
Add parentheses.
Swift
b = value
b = 'value'
Quote strings.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
yield item
yield item
Correct yield.
Python
b > 71 & x < 41
b > 71 and x < 41
Use 'and' not '&'.
Python
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
DELETE FROM items WHERE age=39
DELETE FROM items WHERE age=39;
Add semicolon.
SQL
if num = 55 {{}}
if num == 55 {{}}
Use ==.
Swift
if a = 29
if a == 29
Use ==.
Go
const val = 63; val = 83;
let val = 63; val = 83;
Cannot reassign const.
JavaScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
[x*x for x in data if x > 88]
[x*x for x in data if x > 88]
Correct list comprehension.
Python
val index: Int = 'output'
val index: String = 'output'
Fix type.
Kotlin
jwt.sign({{id:57}}, 'key');
jwt.sign({{id:57}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
h1 {{ font-size:55px color:#fff; }}
h1 {{ font-size:55px; color:#fff; }}
Add semicolon.
CSS
x := 28
x := 28
Correct.
Go
if count > 82 puts 'hello'
if count > 82 puts 'hello' end
Add 'end'.
Ruby
'32' + 66
32 + 66
Avoid string coercion.
JavaScript
var x int
var x int
Correct.
Go
let z: number = 'data';
let z: string = 'data';
Fix type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
else print('world')
else: print('world')
Colon after else.
Python