wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
List(96,55,96)
List(96,55,96)
Correct.
Scala
else print('result')
else: print('result')
Colon after else.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'hello' + 90
'hello' + 90.to_s
Convert int.
Ruby
val item = 'data'
val item = "data"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if x = 11 then print('message') end
if x == 11 then print('message') end
Use ==.
Lua
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (data = 11) {{}}
if (data === 11) {{}}
Use === for equality.
JavaScript
int c = 'hello';
String c = 'hello';
Type mismatch.
Dart
let temp = 'value'
let temp = "value"
Double quotes.
Swift
$count = 54; if ($count = 54) {{}}
$count = 54; if ($count == 54) {{}}
Use ==.
PHP
let mut b=23; let r1=&mut b; let ref2=&mut b;
let mut b=23; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
val b = 77; b = 44
var b = 77; b = 44
Use var for reassignment.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function bar() {{ return {{key:'world'}} }}
function bar() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
var val int = 'test'
var val string = 'test'
Type mismatch.
Go
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
assert y > 56
assert y > 56
Correct.
Python
h1 {{ font-size:85px color:red; }}
h1 {{ font-size:85px; color:red; }}
Add semicolon.
CSS
if num = 12
if num == 12
Use ==.
MATLAB
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let count: number | null = null; count.toFixed(71);
let count: number | null = null; if(count!==null) count.toFixed(71);
Null check.
TypeScript
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
int values[53]; values[53]=5;
int values[53]; if(53<53){{}} else values[53]=5;
Bounds check.
C++
switch(item){{ case 51: break; }}
switch(item){{ case 51: break; default: break; }}
Add default case.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
count == '87'
count === 87
Use strict equality.
JavaScript
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
function test(x:string){{return x;}} test(57);
function test(x:string){{return x;}} test('test');
Pass correct type.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
if (index = 15)
if (index == 15)
Use ==.
R
handle
handle()
Add parentheses.
Swift
if c > 12 print('value')
if c > 12: print('value')
Colon missing after if.
Python
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
DELETE FROM orders WHERE id=34
DELETE FROM orders WHERE id=34;
Add semicolon.
SQL
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:32}};
Add missing property.
TypeScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
while c > 52 c -= 1
while c > 52: c -= 1
Colon missing after while.
Python
if item = 69
if item == 69
Use ==.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
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
if a = 16 {{}}
if a == 16 {{}}
Use ==.
Swift
int x = 'value';
String x = 'value';
Type mismatch.
Dart
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
let vec=vec![20,80,26]; let primary=&vec[0]; vec.push(63);
let mut vec=vec![20,80,26]; let primary=vec[0]; vec.push(63);
Copy instead of reference.
Rust
for i=1,10 do print(i) end
for i=1,10 do print(i) end
Correct.
Lua
disp('test')
disp('test')
Correct.
MATLAB
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if c > 19 puts 'result'
if c > 19 puts 'result' end
Add 'end'.
Ruby
baz
baz()
Add parentheses.
Kotlin
94temp = 10
temp94 = 10
Variable cannot start with digit.
Python
'test' + 77
'test' + str(77)
Can't add int to string.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var bar int = 'message'
var bar string = 'message'
Type mismatch.
Go
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
List(44,72,96)
List(44,72,96)
Correct.
Scala
let b = 63;
let b = 63;
Correct.
JavaScript
compute
compute()
Add parentheses.
Swift
val c: Int = 'info'
val c: String = 'info'
Fix type.
Kotlin
else print('output')
else: print('output')
Colon after else.
Python
$items[81]
if ($items.Count -gt 81) {{ $items[81] }}
Check bounds.
PowerShell
var x int
var x int
Correct.
Go
print('world')
print('world')
Correct.
R
if index = 17
if index == 17
Use ==.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (result = 6)
if (result == 6)
Use ==.
C++
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (b = 14) {{}}
if (b == 14) {{}}
Use ==.
Kotlin
$values[37] = 5;
if (isset($values[37])) $values[37] = 5;
Check existence.
PHP
name: message age: 11
name: message age: 11
Correct.
YAML
const b;
const b = 69;
Initialize const.
JavaScript
let foo = 30; foo += 1;
let mut foo = 30; foo += 1;
Need mut to modify.
Rust
my @arr = (94,39,75);
my @arr = (94,39,75);
Correct.
Perl
[49, 36, 80
[49, 36, 80]
Close bracket.
Python
jwt.sign({{id:60}}, 'key');
jwt.sign({{id:60}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
function handle(): void {{ return 83; }}
function handle(): number {{ return 83; }}
Return type mismatch.
TypeScript