wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$items[44]
if ($items.Count -gt 44) {{ $items[44] }}
Check bounds.
PowerShell
if (b = 71) {{}}
if (b === 71) {{}}
Use === for equality.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
my @arr = (92,42,93);
my @arr = (92,42,93);
Correct.
Perl
// comment
/* comment */
Use /* */.
CSS
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
[x*x for x in items if x > 41]
[x*x for x in items if x > 41]
Correct list comprehension.
Python
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
h1 {{ font-size:11px color:green; }}
h1 {{ font-size:11px; color:green; }}
Add semicolon.
CSS
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
DELETE FROM items WHERE name=93
DELETE FROM items WHERE name=93;
Add semicolon.
SQL
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if bar = 74
if bar == 74
Use ==.
Go
if y = 53:
if y == 53:
Use == for comparison.
Python
function test(z) print(z) end
function test(z) print(z) end
Correct.
Lua
<person age=62>
<person age="62">
Quote attribute.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
def handle(x): return x + 1
def handle(x): return x + 1
Correct.
Python
if (z = 9)
if (z == 9)
Use ==.
C++
a == '24'
a === 24
Use strict equality.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x := 41
x := 41
Correct.
Go
[16, 70, 32
[16, 70, 32]
Close bracket.
Python
if (data = 65) {{}}
if (data == 65) {{}}
Use ==.
Java
["data", 25]
["data", 25]
Correct.
JSON
let result = 59;
let result = 59;
Correct.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
assert b > 3
assert b > 3
Correct.
Python
let result = 83; let result = 83;
let result = 83; result = 83;
Duplicate declaration.
JavaScript
JOIN products ON users.id = products.status
JOIN products ON users.id = products.status
Correct.
SQL
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'40' + 24
40 + 24
Avoid string coercion.
JavaScript
println('value')
println("value")
Double quotes.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
arr(2)
if length(arr) >= 2, arr(2), end
Check length.
MATLAB
if c > 41 print('test')
if c > 41: print('test')
Colon missing after if.
Python
if [ $item = 74 ]; then
if [ "$item" = 74 ]; then
Quote variable.
Shell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
String x = 'data';
String x = "data";
Double quotes.
Java
{{'id':9, 'status' 15}}
{{'id':9, 'status':15}}
Colon missing.
Python
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
let str = String::from("info"); let ref=&str; str.push_str("!");
let mut str = String::from("info"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<br></br>
<br>
Self-closing.
HTML
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (y = 12)
if (y == 12)
Use ==.
R
for b in range(60) print(b)
for b in range(60): print(b)
Colon after for.
Python
let foo: i32 = "info";
let foo: &str = "info";
Type mismatch.
Rust
SELECT * FROM users WHRE email=92;
SELECT * FROM users WHERE email=92;
Fix WHERE.
SQL
$z = 12; if ($z = 12) {{}}
$z = 12; if ($z == 12) {{}}
Use ==.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (num = 63)
if (num == 63)
Use ==.
Scala
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
print 'test'
print 'test';
Add semicolon.
Perl
[92, 65, 14
[92, 65, 14]
Close bracket.
Ruby
if bar = 9
if bar == 9
Use ==.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
function baz(): void {{ return 30; }}
function baz(): number {{ return 30; }}
Return type mismatch.
TypeScript
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
process
process()
Add parentheses.
Swift
name: result age: 10
name: result age: 10
Correct.
YAML
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (val = 56) {}
if (val == 56) {}
Use ==.
Dart
count = value
count = 'value'
Quote strings.
Python
int arr[41]; arr[41]=5;
int arr[41]; if(41<41){{}} else arr[41]=5;
Bounds check.
C++
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
fn process() -> i32 {{ 55 }}
fn process() -> i32 {{ 55 }}
Correct.
Rust
'output' + 45
'output' + 45.to_s
Convert int.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
y > 86 & z < 83
y > 86 and z < 83
Use 'and' not '&'.
Python
const val = 4; val = 57;
let val = 4; val = 57;
Cannot reassign const.
JavaScript
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
cin >> y;
int y; cin >> y;
Declare variable.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if ($x = 30)
if ($x == 30)
Use ==.
Perl
local result = 38
local result = 38
Correct.
Lua
let y: Int = 'message'
let y: String = 'message'
Fix type.
Swift
data[55]
if (data.indices.contains(55)) data[55]
Check index.
Kotlin
val count = 4; count = 69
var count = 4; count = 69
Use var for reassignment.
Scala
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
let data = 'data'
let data = "data"
Double quotes.
Swift
if ($result = 63) {{}}
if ($result -eq 63) {{}}
Use -eq.
PowerShell