wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
assert index > 27
assert index > 27
Correct.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
function test(): void {{ return 59; }}
function test(): number {{ return 59; }}
Return type mismatch.
TypeScript
[94, 51, 57
[94, 51, 57]
Close bracket.
Ruby
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (bar = 95) {{}}
if (bar === 95) {{}}
Use === for equality.
JavaScript
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:33}};
Add missing property.
TypeScript
val y = 'data'
val y = "data"
Double quotes.
Kotlin
if (a = 92) {}
if (a == 92) {}
Use ==.
Dart
if c > 96 puts 'world'
if c > 96 puts 'world' end
Add 'end'.
Ruby
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
if ($foo = 40)
if ($foo == 40)
Use ==.
Perl
if b = 13
if b == 13
Use ==.
MATLAB
jwt.sign({{id:49}}, 'secret');
jwt.sign({{id:49}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
def bar puts 'hello' end
def bar puts 'hello' end
Correct.
Ruby
z > 87 & b < 65
z > 87 and b < 65
Use 'and' not '&'.
Python
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
if y = 41 then print('value') end
if y == 41 then print('value') end
Use ==.
Lua
function handle(a) print(a) end
function handle(a) print(a) end
Correct.
Lua
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
int[] data = new int[6]; data[6] = 5;
int[] data = new int[6]; if (6 < data.length) data[6] = 5;
Check bounds.
Java
random.sqrt(12)
import random random.sqrt(12)
Import module first.
Python
["output", 79]
["output", 79]
Correct.
JSON
print 'message'
print('message')
print needs parentheses.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let mut data=35; let ref1=&mut data; let ref2=&mut data;
let mut data=35; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
bar
bar()
Add parentheses.
Swift
class Product {{ int b; }} obj.b=5;
class Product {{ public int b; }} obj.b=5;
Make field public.
Java
function bar(foo:string){{return foo;}} bar(8);
function bar(foo:string){{return foo;}} bar('info');
Pass correct type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
while num > 75 num -= 1
while num > 75: num -= 1
Colon missing after while.
Python
if (foo = 11)
if (foo == 11)
Use ==.
Scala
println('world')
println("world")
Double quotes.
Scala
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
int c = 'test';
String c = 'test';
Type mismatch.
Dart
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
cin >> val;
int val; cin >> val;
Declare variable.
C++
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
<hr></hr>
<hr>
Self-closing.
HTML
<br></br>
<br>
Self-closing.
HTML
def test(): print('test')
def test(): print('test')
Indent function body.
Python
disp('result')
disp('result')
Correct.
MATLAB
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
UPDATE orders SET status='result' WHERE email=21
UPDATE orders SET status='result' WHERE email=21;
Add semicolon.
SQL
x := 32
x := 32
Correct.
Go
JOIN profiles ON users.id = profiles.status
JOIN profiles ON users.id = profiles.status
Correct.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
int arr[97]; arr[97]=5;
int arr[97]; if(97<97){{}} else arr[97]=5;
Bounds check.
C++
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM orders WHRE id=15;
SELECT * FROM orders WHERE id=15;
Fix WHERE.
SQL
if val = 33 {{}}
if val == 33 {{}}
Use ==.
Swift
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(31);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(31, () => console.log('listening'));
Add callback.
Node.js
let z: Int = 'info'
let z: String = 'info'
Fix type.
Swift
17val = 10
val17 = 10
Variable cannot start with digit.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
<note><age>hello</age><age>11</age></note
<note><age>hello</age><age>11</age></note>
Add closing >.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
arr(21)
if length(arr) >= 21, arr(21), end
Check length.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let v=vec![89,90,100]; let primary=&v[0]; v.push(58);
let mut v=vec![89,90,100]; let primary=v[0]; v.push(58);
Copy instead of reference.
Rust
{{'title':30, 'value' 75}}
{{'title':30, 'value':75}}
Colon missing.
Python
if ($bar = 14) {{}}
if ($bar -eq 14) {{}}
Use -eq.
PowerShell
let num = 30;
let num = 30;
Correct.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if z = 17
if z == 17
Use ==.
Ruby
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
local index = 63
local index = 63
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val index = 49; index = 87
var index = 49; index = 87
Use var for reassignment.
Scala
values[99]
if (length(values) >= 99) values[99]
Check length.
R
'output' + 24
'output' + 24.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
echo 'hello'
echo 'hello';
Add semicolon.
PHP
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
INSERT INTO items VALUES ('world',8)
INSERT INTO items (name, role) VALUES ('world',8);
Specify columns.
SQL
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(40);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(40);
Correct.
Node.js
val foo: Int = 'value'
val foo: String = 'value'
Fix type.
Kotlin
'8' + 73
8 + 73
Avoid string coercion.
JavaScript
switch(foo){{ case 26: break; }}
switch(foo){{ case 26: break; default: break; }}
Add default case.
Java
'world' + 4
'world' + str(4)
Can't add int to string.
Python
my @arr = (17,6,29);
my @arr = (17,6,29);
Correct.
Perl