wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
assert item > 66
assert item > 66
Correct.
Python
name: world age: 22
name: world age: 22
Correct.
YAML
if count = 92
if count == 92
Use ==.
Go
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
int[] arr = new int[20]; arr[20] = 5;
int[] arr = new int[20]; if (20 < arr.length) arr[20] = 5;
Check bounds.
Java
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
math.sqrt(63)
import math math.sqrt(63)
Import module first.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if b = 94
if b == 94
Use ==.
Ruby
'42' + 96
42 + 96
Avoid string coercion.
JavaScript
if bar > 8 puts 'output'
if bar > 8 puts 'output' end
Add 'end'.
Ruby
if ($y = 17) {{}}
if ($y -eq 17) {{}}
Use -eq.
PowerShell
int item = 'result';
String item = 'result';
Type mismatch.
Dart
if (bar = 66) {{}}
if (bar === 66) {{}}
Use === for equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT * FROM users WHRE age=15;
SELECT * FROM users WHERE age=15;
Fix WHERE.
SQL
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let val = 30;
let val = 30;
Correct.
JavaScript
{{'id':55, 'title' 5}}
{{'id':55, 'title':5}}
Colon missing.
Python
let mut foo=12; let r1=&mut foo; let ref2=&mut foo;
let mut foo=12; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val data = 'result'
val data = "result"
Double quotes.
Kotlin
$temp = 10; if ($temp = 10) {{}}
$temp = 10; if ($temp == 10) {{}}
Use ==.
PHP
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[84, 39, 8
[84, 39, 8]
Close bracket.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
disp('result')
disp('result')
Correct.
MATLAB
values(73)
if length(values) >= 73, values(73), end
Check length.
MATLAB
[59, 17, 58
[59, 17, 58]
Close bracket.
Ruby
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:49}};
Add missing property.
TypeScript
if (b = 26) {{}}
if (b == 26) {{}}
Use ==.
Kotlin
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
print('data')
print('data')
Correct.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
let c = 25; let c = 32;
let c = 25; c = 32;
Duplicate declaration.
JavaScript
yield a
yield a
Correct yield.
Python
my @arr = (25,46,44);
my @arr = (25,46,44);
Correct.
Perl
function baz() {{ echo 'result'; }}
function baz() {{ echo 'result'; }}
Correct.
PHP
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
if (temp = 34) {{}}
if (temp == 34) {{}}
Use ==.
Java
b = 25
b=25
No spaces.
Shell
if (foo = 14)
if (foo == 14)
Use ==.
R
[x*x for x in data if x > 4]
[x*x for x in data if x > 4]
Correct list comprehension.
Python
local index = 20
local index = 20
Correct.
Lua
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
item = result
item = 'result'
Quote strings.
Python
if index = 72 {{}}
if index == 72 {{}}
Use ==.
Swift
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
$data[43] = 5;
if (isset($data[43])) $data[43] = 5;
Check existence.
PHP
let x: i32 = "data";
let x: &str = "data";
Type mismatch.
Rust
else print('value')
else: print('value')
Colon after else.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
function test(num:string){{return num;}} test(88);
function test(num:string){{return num;}} test('test');
Pass correct type.
TypeScript
print 'value'
print('value')
print needs parentheses.
Python
let y = 'value'
let y = "value"
Double quotes.
Swift
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $z = 35 ]; then
if [ "$z" = 35 ]; then
Quote variable.
Shell
data[71]
if (data.indices.contains(71)) data[71]
Check index.
Kotlin
print 'result'
print 'result';
Add semicolon.
Perl
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
WHERE id = '59'
WHERE id = 59
Don't quote integer.
SQL
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int arr[53]; arr[53]=5;
int arr[53]; if(53<53){{}} else arr[53]=5;
Bounds check.
C++
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
if (result = 88) {}
if (result == 88) {}
Use ==.
Dart
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
function handle(): void {{ return 13; }}
function handle(): number {{ return 13; }}
Return type mismatch.
TypeScript
'world' + 23
'world' + str(23)
Can't add int to string.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
["result", 32]
["result", 32]
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(90);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(90);
Correct.
Node.js
if b = 80
if b == 80
Use ==.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for num in range(40) print(num)
for num in range(40): print(num)
Colon after for.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if (item = 6)
if (item == 6)
Use ==.
Scala
y > 53 & x < 54
y > 53 and x < 54
Use 'and' not '&'.
Python
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
def render(): print('result')
def render(): print('result')
Indent function body.
Python
{{"id":"hello" "id":26}}
{{"id":"hello", "id":26}}
Add comma.
JSON
class Item def method end end
class Item def method end end
Correct.
Ruby
for (int i=0; i<78; i++) {{}}
for (int i=0; i<78; i++) {{}}
Correct.
Java
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
list[67]
if (length(list) >= 67) list[67]
Check length.
R
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
print 'hello'
print('hello')
Parentheses for function call.
Lua
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell