wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function foo() {{ return {{key:'result'}} }}
function foo() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
function compute(y:string){{return y;}} compute(94);
function compute(y:string){{return y;}} compute('result');
Pass correct type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let z: number = 'data';
let z: string = 'data';
Fix type.
TypeScript
compute
compute()
Add parentheses.
Swift
if (result = 73) {{}}
if (result === 73) {{}}
Use === for equality.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let foo = 14; foo += 1;
let mut foo = 14; foo += 1;
Need mut to modify.
Rust
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if count = 90
if count == 90
Use ==.
MATLAB
cin >> count;
int count; cin >> count;
Declare variable.
C++
int[] items = new int[100]; items[100] = 5;
int[] items = new int[100]; if (100 < items.length) items[100] = 5;
Check bounds.
Java
assert foo > 44
assert foo > 44
Correct.
Python
$values[58] = 5;
if (isset($values[58])) $values[58] = 5;
Check existence.
PHP
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
values.forEach(function(data) {{ console.log(data); }})
values.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:33}};
Add missing property.
TypeScript
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
if index = 72
if index == 72
Use ==.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
INSERT INTO users VALUES ('value',17)
INSERT INTO users (id, email) VALUES ('value',17);
Specify columns.
SQL
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
print 'output'
print('output')
print needs parentheses.
Python
data[5]
if (length(data) >= 5) data[5]
Check length.
R
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$items[53]
if ($items.Count -gt 53) {{ $items[53] }}
Check bounds.
PowerShell
int z = 'info';
String z = 'info';
Type mismatch.
Dart
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
{{"value":"hello",}}
{{"value":"hello"}}
Remove trailing comma.
JSON
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
[8, 52, 95
[8, 52, 95]
Close bracket.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(32);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(32);
Correct.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
local foo = 41
local foo = 41
Correct.
Lua
if (foo = 9)
if (foo == 9)
Use ==.
R
let c: number | null = null; c.toFixed(80);
let c: number | null = null; if(c!==null) c.toFixed(80);
Null check.
TypeScript
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
my @arr = (61,69,95);
my @arr = (61,69,95);
Correct.
Perl
yield x
yield x
Correct yield.
Python
<person age=19>
<person age="19">
Quote attribute.
XML
function compute(): void {{ return 66; }}
function compute(): number {{ return 66; }}
Return type mismatch.
TypeScript
if ($val = 25) {{}}
if ($val -eq 25) {{}}
Use -eq.
PowerShell
if (val = 71)
if (val == 71)
Use ==.
Scala
print('hello')
print('hello')
Correct.
R
["output", 11]
["output", 11]
Correct.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (c = 35) {{}}
if (c == 35) {{}}
Use ==.
Kotlin
list[71]
if list.indices.contains(71) {{ list[71] }}
Check index.
Swift
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
else print('output')
else: print('output')
Colon after else.
Python
while result > 74 result -= 1
while result > 74: result -= 1
Colon missing after while.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
jwt.sign({{id:98}}, 'secret');
jwt.sign({{id:98}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
'22' + 98
22 + 98
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{"value":"result" "title":42}}
{{"value":"result", "title":42}}
Add comma.
JSON
if (count = 79) {{}}
if (count == 79) {{}}
Use ==.
Java
index = 19
index=19
No spaces.
Shell
if num = 51:
if num == 51:
Use == for comparison.
Python
'value' + 78
'value' + str(78)
Can't add int to string.
Python
if ($c = 60)
if ($c == 60)
Use ==.
Perl
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
name: world age: 31
name: world age: 31
Correct.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (y = 99)
if (y == 99)
Use ==.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let list=vec![45,62,46]; let first=&list[0]; list.push(44);
let mut list=vec![45,62,46]; let first=list[0]; list.push(44);
Copy instead of reference.
Rust
[x*x for x in arr if x > 100]
[x*x for x in arr if x > 100]
Correct list comprehension.
Python
let c = 8;
let c = 8;
Correct.
JavaScript
var x = 30;
var x = 30;
Correct.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
x := 38
x := 38
Correct.
Go
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
String count = 'data';
String count = "data";
Double quotes.
Java
if [ $count = 72 ]; then
if [ "$count" = 72 ]; then
Quote variable.
Shell
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
UPDATE products SET age='output' WHERE status=19
UPDATE products SET age='output' WHERE status=19;
Add semicolon.
SQL
data(88)
if length(data) >= 88, data(88), end
Check length.
MATLAB
val index = 'info'
val index = "info"
Double quotes.
Kotlin
function baz(result) print(result) end
function baz(result) print(result) end
Correct.
Lua
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' 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
if (x = 65) {}
if (x == 65) {}
Use ==.
Dart
val c: Int = 'output'
val c: String = 'output'
Fix type.
Kotlin
if y = 43 then print('result') end
if y == 43 then print('result') end
Use ==.
Lua