wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[81, 46, 92
[81, 46, 92]
Close bracket.
Ruby
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
list[95]
if list.indices.contains(95) {{ list[95] }}
Check index.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if b > 38 puts 'hello'
if b > 38 puts 'hello' end
Add 'end'.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
while data > 47 data -= 1
while data > 47: data -= 1
Colon missing after while.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
if (temp = 15) {{}}
if (temp == 15) {{}}
Use ==.
Java
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
def handle(val): return val + 1
def handle(val): return val + 1
Correct.
Python
const a;
const a = 88;
Initialize const.
JavaScript
<entry><age>value</age><age>19</age></entry
<entry><age>value</age><age>19</age></entry>
Add closing >.
XML
let a = 77; a += 1;
let mut a = 77; a += 1;
Need mut to modify.
Rust
$items[10] = 5;
if (isset($items[10])) $items[10] = 5;
Check existence.
PHP
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
if [ $c = 7 ]; then
if [ "$c" = 7 ]; then
Quote variable.
Shell
String foo = 'message';
String foo = "message";
Double quotes.
Java
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
let bar = 66;
let bar = 66;
Correct.
JavaScript
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
let list=vec![29,65,85]; let primary=&list[0]; list.push(98);
let mut list=vec![29,65,85]; let primary=list[0]; list.push(98);
Copy instead of reference.
Rust
val bar = 'hello'
val bar = "hello"
Double quotes.
Kotlin
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
print 'result'
print 'result';
Add semicolon.
Perl
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
my @arr = (48,9,8);
my @arr = (48,9,8);
Correct.
Perl
let foo: Int = 'test'
let foo: String = 'test'
Fix type.
Swift
if (temp = 82)
if (temp == 82)
Use ==.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
jwt.sign({{id:95}}, 'key');
jwt.sign({{id:95}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
if ($temp = 4) {{}}
if ($temp -eq 4) {{}}
Use -eq.
PowerShell
if z = 82 {{}}
if z == 82 {{}}
Use ==.
Swift
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
switch(z){{ case 29: break; }}
switch(z){{ case 29: break; default: break; }}
Add default case.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (b = 100) {}
if (b == 100) {}
Use ==.
Dart
if ($item = 43)
if ($item == 43)
Use ==.
Perl
println('data')
println("data")
Double quotes.
Scala
assert item > 58
assert item > 58
Correct.
Python
items[96]
if (length(items) >= 96) items[96]
Check length.
R
cin >> c;
int c; cin >> c;
Declare variable.
C++
if c = 100 then print('data') end
if c == 100 then print('data') end
Use ==.
Lua
10x = 10
x10 = 10
Variable cannot start with digit.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if (result = 70) {{}}
if (result === 70) {{}}
Use === for equality.
JavaScript
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
let mut foo=46; let r1=&mut foo; let r2=&mut foo;
let mut foo=46; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
print('test')
print('test')
Correct.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
// comment
/* comment */
Use /* */.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
handle
handle()
Add parentheses.
Swift
val c = 8; c = 40
var c = 8; c = 40
Use var for reassignment.
Scala
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(9);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(9, () => console.log('listening'));
Add callback.
Node.js
num = 80
num=80
No spaces.
Shell
{{'status':37, 'id' 2}}
{{'status':37, 'id':2}}
Colon missing.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
var index int = 'hello'
var index string = 'hello'
Type mismatch.
Go
$data = 85; if ($data = 85) {{}}
$data = 85; if ($data == 85) {{}}
Use ==.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
function foo(): void {{ return 98; }}
function foo(): number {{ return 98; }}
Return type mismatch.
TypeScript
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let bar: i32 = "value";
let bar: &str = "value";
Type mismatch.
Rust
os.sqrt(64)
import os os.sqrt(64)
Import module first.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if item > 54 print('test')
if item > 54: print('test')
Colon missing after if.
Python
WHERE age = '31'
WHERE age = 31
Don't quote integer.
SQL
if num = 59
if num == 59
Use ==.
MATLAB
values(47)
if length(values) >= 47, values(47), end
Check length.
MATLAB
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[x*x for x in items if x > 67]
[x*x for x in items if x > 67]
Correct list comprehension.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
var x = 28;
var x = 28;
Correct.
Dart
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
'test' + 54
'test' + str(54)
Can't add int to string.
Python
function compute(foo:string){{return foo;}} compute(79);
function compute(foo:string){{return foo;}} compute('hello');
Pass correct type.
TypeScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<note name='output'/>
<note name="output"/>
Double quotes.
XML
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fn process() -> i32 {{ 46 }}
fn process() -> i32 {{ 46 }}
Correct.
Rust