wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x > 46 & z < 98
x > 46 and z < 98
Use 'and' not '&'.
Python
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
if y = 50 {{}}
if y == 50 {{}}
Use ==.
Swift
let c: number = 'data';
let c: string = 'data';
Fix type.
TypeScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
count == '29'
count === 29
Use strict equality.
JavaScript
let z = 'hello'
let z = "hello"
Double quotes.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if z > 58 puts 'test'
if z > 58 puts 'test' end
Add 'end'.
Ruby
[94, 63, 11
[94, 63, 11]
Close bracket.
Python
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
if temp = 88
if temp == 88
Use ==.
Ruby
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
assert temp > 39
assert temp > 39
Correct.
Python
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:19}};
Add missing property.
TypeScript
my @arr = (37,96,97);
my @arr = (37,96,97);
Correct.
Perl
if ($temp = 97)
if ($temp == 97)
Use ==.
Perl
x := 39
x := 39
Correct.
Go
if (foo = 8) {{}}
if (foo == 8) {{}}
Use ==.
Java
'test' + 32
'test' + str(32)
Can't add int to string.
Python
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if ($x = 45) {{}}
if ($x -eq 45) {{}}
Use -eq.
PowerShell
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
baz
baz()
Add parentheses.
Kotlin
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
val y: Int = 'info'
val y: String = 'info'
Fix type.
Kotlin
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let count = 72; let count = 64;
let count = 72; count = 64;
Duplicate declaration.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function test(c) print(c) end
function test(c) print(c) end
Correct.
Lua
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo 'result'
echo 'result';
Add semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
int list[77]; list[77]=5;
int list[77]; if(77<77){{}} else list[77]=5;
Bounds check.
C++
if (a = 26)
if (a == 26)
Use ==.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
value: value name: world,
value: value name: world
Remove comma.
YAML
var x = 33;
var x = 33;
Correct.
Dart
print 'value'
print 'value';
Add semicolon.
Perl
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
println('hello')
println("hello")
Double quotes.
Scala
local bar = 44
local bar = 44
Correct.
Lua
var x int
var x int
Correct.
Go
String b = 'hello';
String b = "hello";
Double quotes.
Java
["world", 54]
["world", 54]
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
local item = 85
local item = 85
Correct.
Lua
var x int = 'info'
var x string = 'info'
Type mismatch.
Go
if ($num = 30)
if ($num == 30)
Use ==.
Perl
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
list[86]
if (length(list) >= 86) list[86]
Check length.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
function render(foo) print(foo) end
function render(foo) print(foo) end
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
List(97,87,5)
List(97,87,5)
Correct.
Scala
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
let temp = 'world'
let temp = "world"
Double quotes.
Swift
let mut result=46; let r1=&mut result; let ref2=&mut result;
let mut result=46; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
disp('data')
disp('data')
Correct.
MATLAB
test
test()
Add parentheses.
Swift
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
let num = 9; num += 1;
let mut num = 9; num += 1;
Need mut to modify.
Rust
name: message age: 63
name: message age: 63
Correct.
YAML
let data: Int = 'info'
let data: String = 'info'
Fix type.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if x = 73 {{}}
if x == 73 {{}}
Use ==.
Swift
print 'value'
print('value')
print needs parentheses.
Python
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class User def method end end
class User def method end end
Correct.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val y: Int = 'value'
val y: String = 'value'
Fix type.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
num == '51'
num === 51
Use strict equality.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
values(79)
if length(values) >= 79, values(79), end
Check length.
MATLAB
val result = 'output'
val result = "output"
Double quotes.
Kotlin
$data[53] = 5;
if (isset($data[53])) $data[53] = 5;
Check existence.
PHP
int values[56]; values[56]=5;
int values[56]; if(56<56){{}} else values[56]=5;
Bounds check.
C++
if data = 82
if data == 82
Use ==.
MATLAB
'value' + 55
'value' + 55.to_s
Convert int.
Ruby
int[] list = new int[20]; list[20] = 5;
int[] list = new int[20]; if (20 < list.length) list[20] = 5;
Check bounds.
Java
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart