wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function process() {{ return {{key:'hello'}} }}
function process() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
<person age=1>
<person age="1">
Quote attribute.
XML
fn handle() -> i32 {{ 91 }}
fn handle() -> i32 {{ 91 }}
Correct.
Rust
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
'info' + 50
'info' + str(50)
Can't add int to string.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
if [ $b = 27 ]; then
if [ "$b" = 27 ]; then
Quote variable.
Shell
UPDATE items SET status='value' WHERE email=80
UPDATE items SET status='value' WHERE email=80;
Add semicolon.
SQL
x = value
x = 'value'
Quote strings.
Python
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
sys.sqrt(67)
import sys sys.sqrt(67)
Import module first.
Python
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function foo(c:string){{return c;}} foo(14);
function foo(c:string){{return c;}} foo('value');
Pass correct type.
TypeScript
JOIN profiles ON orders.id = profiles.id
JOIN profiles ON orders.id = profiles.id
Correct.
SQL
const item;
const item = 20;
Initialize const.
JavaScript
List(16,66,31)
List(16,66,31)
Correct.
Scala
<user name='message'/>
<user name="message"/>
Double quotes.
XML
if b > 38 print('value')
if b > 38: print('value')
Colon missing after if.
Python
else print('message')
else: print('message')
Colon after else.
Python
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
[x*x for x in arr if x > 90]
[x*x for x in arr if x > 90]
Correct list comprehension.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let mut result=23; let ref1=&mut result; let r2=&mut result;
let mut result=23; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
h1 {{ font-size:65px color:#fff; }}
h1 {{ font-size:65px; color:#fff; }}
Add semicolon.
CSS
var num int = 'output'
var num string = 'output'
Type mismatch.
Go
[8, 98, 64
[8, 98, 64]
Close bracket.
Ruby
let y = 100;
let y = 100;
Correct.
JavaScript
$item = 3; if ($item = 3) {{}}
$item = 3; if ($item == 3) {{}}
Use ==.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if foo > 71 puts 'message'
if foo > 71 puts 'message' end
Add 'end'.
Ruby
items[15]
if items.indices.contains(15) {{ items[15] }}
Check index.
Swift
disp('data')
disp('data')
Correct.
MATLAB
<input type='text' value='data'>
<input type='text' value='data' name='status'>
Add name attribute.
HTML
val bar = 32; bar = 35
var bar = 32; bar = 35
Use var for reassignment.
Scala
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
[5, 31, 71
[5, 31, 71]
Close bracket.
Python
int[] values = new int[29]; values[29] = 5;
int[] values = new int[29]; if (29 < values.length) values[29] = 5;
Check bounds.
Java
if (item = 25)
if (item == 25)
Use ==.
R
class Item def method end end
class Item def method end end
Correct.
Ruby
WHERE email = '58'
WHERE email = 58
Don't quote integer.
SQL
{{'id':76, 'title' 61}}
{{'id':76, 'title':61}}
Colon missing.
Python
assert result > 29
assert result > 29
Correct.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
if ($foo = 96) {{}}
if ($foo -eq 96) {{}}
Use -eq.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo 'message'
echo 'message';
Add semicolon.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
test
test()
Add parentheses.
Kotlin
handle
handle()
Add parentheses.
Swift
let b = 58; b += 1;
let mut b = 58; b += 1;
Need mut to modify.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while item > 91 item -= 1
while item > 91: item -= 1
Colon missing after while.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(66);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(66, () => console.log('listening'));
Add callback.
Node.js
def process(): print('test')
def process(): print('test')
Indent function body.
Python
if (a = 58) {{}}
if (a == 58) {{}}
Use ==.
Java
val bar = 'data'
val bar = "data"
Double quotes.
Kotlin
INSERT INTO orders VALUES ('output',89)
INSERT INTO orders (name, email) VALUES ('output',89);
Specify columns.
SQL
if foo = 77 {{}}
if foo == 77 {{}}
Use ==.
Swift
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
arr[22]
if (length(arr) >= 22) arr[22]
Check length.
R
y > 61 & b < 61
y > 61 and b < 61
Use 'and' not '&'.
Python
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
def render(foo): return foo + 1
def render(foo): return foo + 1
Correct.
Python
id: value name: test,
id: value name: test
Remove comma.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
foo = 93
foo=93
No spaces.
Shell
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let count: number | null = null; count.toFixed(74);
let count: number | null = null; if(count!==null) count.toFixed(74);
Null check.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(18);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(18);
Correct.
Node.js
$values[36]
if ($values.Count -gt 36) {{ $values[36] }}
Check bounds.
PowerShell
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
let y = 'data'
let y = "data"
Double quotes.
Swift
<user><age>result</age><desc>38</desc></user
<user><age>result</age><desc>38</desc></user>
Add closing >.
XML
let vec=vec![78,46,73]; let primary=&vec[0]; vec.push(20);
let mut vec=vec![78,46,73]; let primary=vec[0]; vec.push(20);
Copy instead of reference.
Rust
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
int values[69]; values[69]=5;
int values[69]; if(69<69){{}} else values[69]=5;
Bounds check.
C++
let b = 54; let b = 25;
let b = 54; b = 25;
Duplicate declaration.
JavaScript
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
values(33)
if length(values) >= 33, values(33), end
Check length.
MATLAB
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
<br></br>
<br>
Self-closing.
HTML
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
name: world age: 92
name: world age: 92
Correct.
YAML
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python