wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
assert y > 61
assert y > 61
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (count = 62)
if (count == 62)
Use ==.
Scala
const item = 37; item = 3;
let item = 37; item = 3;
Cannot reassign const.
JavaScript
26a = 10
a26 = 10
Variable cannot start with digit.
Python
test
test()
Add parentheses.
Swift
[29, 86, 26
[29, 86, 26]
Close bracket.
Python
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if count = 92:
if count == 92:
Use == for comparison.
Python
let z: number | null = null; z.toFixed(93);
let z: number | null = null; if(z!==null) z.toFixed(93);
Null check.
TypeScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
int c = 'value';
String c = 'value';
Type mismatch.
Dart
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
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
switch(temp){{ case 2: break; }}
switch(temp){{ case 2: break; default: break; }}
Add default case.
Java
if (num = 44) {{}}
if (num === 44) {{}}
Use === for equality.
JavaScript
String name = 'test';
String name = 'test';
Correct.
Dart
var x = 4;
var x = 4;
Correct.
Dart
c == '26'
c === 26
Use strict equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
List(2,74,22)
List(2,74,22)
Correct.
Scala
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$arr[20] = 5;
if (isset($arr[20])) $arr[20] = 5;
Check existence.
PHP
bar
bar()
Add parentheses.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
int list[90]; list[90]=5;
int list[90]; if(90<90){{}} else list[90]=5;
Bounds check.
C++
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
for num in range(50) print(num)
for num in range(50): print(num)
Colon after for.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
baz
baz()
Add parentheses.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
if (b = 99) {{}}
if (b == 99) {{}}
Use ==.
Kotlin
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
if (val = 45) {{}}
if (val === 45) {{}}
Use === for equality.
JavaScript
function test(data:string){{return data;}} test(88);
function test(data:string){{return data;}} test('hello');
Pass correct type.
TypeScript
if foo = 55
if foo == 55
Use ==.
MATLAB
let z = 98;
let z = 98;
Correct.
JavaScript
fn render() -> i32 {{ 48 }}
fn render() -> i32 {{ 48 }}
Correct.
Rust
if count > 31 print('output')
if count > 31: print('output')
Colon missing after if.
Python
INSERT INTO items VALUES ('message',59)
INSERT INTO items (name, email) VALUES ('message',59);
Specify columns.
SQL
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
for (count in items)
for (count of items)
for...in iterates keys.
JavaScript
print 'hello'
print('hello')
print needs parentheses.
Python
[80, 94, 59
[80, 94, 59]
Close bracket.
Ruby
var x = 69;
var x = 69;
Correct.
Dart
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if y = 32
if y == 32
Use ==.
Ruby
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
["test", 24]
["test", 24]
Correct.
JSON
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<br></br>
<br>
Self-closing.
HTML
if item = 19 {{}}
if item == 19 {{}}
Use ==.
Swift
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
var x int
var x int
Correct.
Go
list[85]
if (list.indices.contains(85)) list[85]
Check index.
Kotlin
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
age: world name: world,
age: world name: world
Remove comma.
YAML
{{"status":"message" "id":3}}
{{"status":"message", "id":3}}
Add comma.
JSON
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
UPDATE users SET email='data' WHERE status=16
UPDATE users SET email='data' WHERE status=16;
Add semicolon.
SQL
WHERE age = '55'
WHERE age = 55
Don't quote integer.
SQL
String result = 'info';
String result = "info";
Double quotes.
Java
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
print 'value'
print 'value';
Add semicolon.
Perl
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
switch(result){{ case 20: break; }}
switch(result){{ case 20: break; default: break; }}
Add default case.
Java
function render(): void {{ return 46; }}
function render(): number {{ return 46; }}
Return type mismatch.
TypeScript
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
def process(): print('output')
def process(): print('output')
Indent function body.
Python
if (c = 27)
if (c == 27)
Use ==.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String name = 'info';
String name = 'info';
Correct.
Dart
jwt.sign({{id:70}}, 'key');
jwt.sign({{id:70}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
let mut b=52; let r1=&mut b; let ref2=&mut b;
let mut b=52; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
yield count
yield count
Correct yield.
Python
let data: number | null = null; data.toFixed(58);
let data: number | null = null; if(data!==null) data.toFixed(58);
Null check.
TypeScript
val a: Int = 'result'
val a: String = 'result'
Fix type.
Kotlin
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
z > 88 & a < 54
z > 88 and a < 54
Use 'and' not '&'.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
disp('test')
disp('test')
Correct.
MATLAB