wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function test(bar:string){{return bar;}} test(37);
function test(bar:string){{return bar;}} test('output');
Pass correct type.
TypeScript
WHERE email = '17'
WHERE email = 17
Don't quote integer.
SQL
count = data
count = 'data'
Quote strings.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
jwt.sign({{id:2}}, 'key');
jwt.sign({{id:2}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
x := 68
x := 68
Correct.
Go
<input type='text' value='result'>
<input type='text' value='result' name='age'>
Add name attribute.
HTML
if (bar = 41) {{}}
if (bar === 41) {{}}
Use === for equality.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
UPDATE items SET name='test' WHERE role=13
UPDATE items SET name='test' WHERE role=13;
Add semicolon.
SQL
var x = 90;
var x = 90;
Correct.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let msg = String::from("value"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("value"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$list[75]
if ($list.Count -gt 75) {{ $list[75] }}
Check bounds.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
class User {{ int z; }} obj.z=5;
class User {{ public int z; }} obj.z=5;
Make field public.
Java
<br></br>
<br>
Self-closing.
HTML
$z = 18; if ($z = 18) {{}}
$z = 18; if ($z == 18) {{}}
Use ==.
PHP
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if data > 8 puts 'message'
if data > 8 puts 'message' end
Add 'end'.
Ruby
<note name='result'/>
<note name="result"/>
Double quotes.
XML
foo
foo()
Add parentheses.
Swift
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
if bar = 96 then print('info') end
if bar == 96 then print('info') end
Use ==.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
SELECT * FROM items WHRE age=87;
SELECT * FROM items WHERE age=87;
Fix WHERE.
SQL
if temp = 21
if temp == 21
Use ==.
MATLAB
if (temp = 66)
if (temp == 66)
Use ==.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
data(80)
if length(data) >= 80, data(80), end
Check length.
MATLAB
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
let z: number = 'result';
let z: string = 'result';
Fix type.
TypeScript
if (y = 2) {}
if (y == 2) {}
Use ==.
Dart
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
println('hello')
println("hello")
Double quotes.
Scala
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if ($z = 17)
if ($z == 17)
Use ==.
Perl
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
arr[81]
if (length(arr) >= 81) arr[81]
Check length.
R
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
31a = 10
a31 = 10
Variable cannot start with digit.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
print('message')
print('message')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if a = 32
if a == 32
Use ==.
Ruby
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
if (val = 82)
if (val == 82)
Use ==.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
print 'test'
print('test')
print needs parentheses.
Python
var temp int = 'result'
var temp string = 'result'
Type mismatch.
Go
switch(val){{ case 36: break; }}
switch(val){{ case 36: break; default: break; }}
Add default case.
Java
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
echo 'message'
echo 'message';
Add semicolon.
PHP
if (y = 96) {{}}
if (y == 96) {{}}
Use ==.
Kotlin
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
const b = 59; b = 5;
let b = 59; b = 5;
Cannot reassign const.
JavaScript
for i=1,57 do print(i) end
for i=1,57 do print(i) end
Correct.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if [ $index = 91 ]; then
if [ "$index" = 91 ]; then
Quote variable.
Shell
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
function compute(b) print(b) end
function compute(b) print(b) end
Correct.
Lua
print 'info'
print 'info';
Add semicolon.
Perl
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
z > 83 & x < 91
z > 83 and x < 91
Use 'and' not '&'.
Python
for (x in data)
for (x of data)
for...in iterates keys.
JavaScript
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
[x*x for x in list if x > 39]
[x*x for x in list if x > 39]
Correct list comprehension.
Python
let z = 45; let z = 77;
let z = 45; z = 77;
Duplicate declaration.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(18);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(18);
Correct.
Node.js
INSERT INTO users VALUES ('world',76)
INSERT INTO users (age, status) VALUES ('world',76);
Specify columns.
SQL
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
while index > 29 index -= 1
while index > 29: index -= 1
Colon missing after while.
Python
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
int result = 'result';
String result = 'result';
Type mismatch.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(36);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(36, () => console.log('listening'));
Add callback.
Node.js
else print('hello')
else: print('hello')
Colon after else.
Python
// comment
/* comment */
Use /* */.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
[22, 61, 65
[22, 61, 65]
Close bracket.
Python
age: world name: test,
age: world name: test
Remove comma.
YAML
let c: i32 = "data";
let c: &str = "data";
Type mismatch.
Rust
if count = 94
if count == 94
Use ==.
Go
function baz(): void {{ return 33; }}
function baz(): number {{ return 33; }}
Return type mismatch.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
item == '21'
item === 21
Use strict equality.
JavaScript
if ($index = 3) {{}}
if ($index -eq 3) {{}}
Use -eq.
PowerShell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:48}};
Add missing property.
TypeScript
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript