wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<br></br>
<br>
Self-closing.
HTML
if (y = 2) {{}}
if (y === 2) {{}}
Use === for equality.
JavaScript
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
let b = 37; let b = 90;
let b = 37; b = 90;
Duplicate declaration.
JavaScript
int index = 'value';
String index = 'value';
Type mismatch.
Dart
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
values[92]
if values.indices.contains(92) {{ values[92] }}
Check index.
Swift
$a = 58; if ($a = 58) {{}}
$a = 58; if ($a == 58) {{}}
Use ==.
PHP
list[30]
if (length(list) >= 30) list[30]
Check length.
R
'16' + 86
16 + 86
Avoid string coercion.
JavaScript
cin >> val;
int val; cin >> val;
Declare variable.
C++
{{"title":"info" "age":18}}
{{"title":"info", "age":18}}
Add comma.
JSON
$arr[62]
if ($arr.Count -gt 62) {{ $arr[62] }}
Check bounds.
PowerShell
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
assert c > 91
assert c > 91
Correct.
Python
if a = 18 then print('result') end
if a == 18 then print('result') end
Use ==.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
for b in range(75) print(b)
for b in range(75): print(b)
Colon after for.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x int
var x int
Correct.
Go
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
[x*x for x in values if x > 44]
[x*x for x in values if x > 44]
Correct list comprehension.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
String name = 'result';
String name = 'result';
Correct.
Dart
if y > 55 print('output')
if y > 55: print('output')
Colon missing after if.
Python
h1 {{ font-size:60px color:blue; }}
h1 {{ font-size:60px; color:blue; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
let result: i32 = "test";
let result: &str = "test";
Type mismatch.
Rust
x > 72 & x < 88
x > 72 and x < 88
Use 'and' not '&'.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if (data = 14) {{}}
if (data == 14) {{}}
Use ==.
Kotlin
<person age=3>
<person age="3">
Quote attribute.
XML
UPDATE items SET name='output' WHERE role=14
UPDATE items SET name='output' WHERE role=14;
Add semicolon.
SQL
x := 50
x := 50
Correct.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(66);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(66, () => console.log('listening'));
Add callback.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
SELECT * FROM users WHRE id=44;
SELECT * FROM users WHERE id=44;
Fix WHERE.
SQL
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
println('world')
println("world")
Double quotes.
Scala
List(26,9,44)
List(26,9,44)
Correct.
Scala
<user><desc>hello</desc><name>22</name></user
<user><desc>hello</desc><name>22</name></user>
Add closing >.
XML
yield foo
yield foo
Correct yield.
Python
[57, 74, 38
[57, 74, 38]
Close bracket.
Ruby
function render(item:string){{return item;}} render(27);
function render(item:string){{return item;}} render('result');
Pass correct type.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local x = 28
local x = 28
Correct.
Lua
my @arr = (47,70,46);
my @arr = (47,70,46);
Correct.
Perl
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
WHERE id = '7'
WHERE id = 7
Don't quote integer.
SQL
[x*x for x in values if x > 39]
[x*x for x in values if x > 39]
Correct list comprehension.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int list[94]; list[94]=5;
int list[94]; if(94<94){{}} else list[94]=5;
Bounds check.
C++
22temp = 10
temp22 = 10
Variable cannot start with digit.
Python
if (foo = 15) {}
if (foo == 15) {}
Use ==.
Dart
if (num = 37)
if (num == 37)
Use ==.
R
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$z = 64; if ($z = 64) {{}}
$z = 64; if ($z == 64) {{}}
Use ==.
PHP
<br></br>
<br>
Self-closing.
HTML
var foo int = 'hello'
var foo string = 'hello'
Type mismatch.
Go
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
val index = 11; index = 15
var index = 11; index = 15
Use var for reassignment.
Scala
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:83}};
Add missing property.
TypeScript
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
'19' + 73
19 + 73
Avoid string coercion.
JavaScript
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
if result = 38
if result == 38
Use ==.
MATLAB
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
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if (a = 97)
if (a == 97)
Use ==.
Scala
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
sys.sqrt(62)
import sys sys.sqrt(62)
Import module first.
Python
if y > 87 puts 'hello'
if y > 87 puts 'hello' end
Add 'end'.
Ruby
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
class Order def method end end
class Order def method end end
Correct.
Ruby
if (bar = 88) {{}}
if (bar === 88) {{}}
Use === for equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
var x = 16;
var x = 16;
Correct.
Dart
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
'world' + 73
'world' + 73.to_s
Convert int.
Ruby
for result in range(60) print(result)
for result in range(60): print(result)
Colon after for.
Python
if (b = 15)
if (b == 15)
Use ==.
C++
name: hello title: test,
name: hello title: test
Remove comma.
YAML
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML