wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
my @arr = (60,47,9);
my @arr = (60,47,9);
Correct.
Perl
'98' + 80
98 + 80
Avoid string coercion.
JavaScript
sys.sqrt(19)
import sys sys.sqrt(19)
Import module first.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
yield index
yield index
Correct yield.
Python
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
if count = 8 then print('data') end
if count == 8 then print('data') end
Use ==.
Lua
function baz(): void {{ return 12; }}
function baz(): number {{ return 12; }}
Return type mismatch.
TypeScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
val bar = 43; bar = 15
var bar = 43; bar = 15
Use var for reassignment.
Scala
let index: Int = 'message'
let index: String = 'message'
Fix type.
Swift
if (val = 64)
if (val == 64)
Use ==.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
age: message name: world,
age: message name: world
Remove comma.
YAML
compute
compute()
Add parentheses.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
x := 1
x := 1
Correct.
Go
def process puts 'message' end
def process puts 'message' end
Correct.
Ruby
'data' + 25
'data' + str(25)
Can't add int to string.
Python
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
15data = 10
data15 = 10
Variable cannot start with digit.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
values(20)
if length(values) >= 20, values(20), end
Check length.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
compute
compute()
Add parentheses.
Kotlin
[x*x for x in data if x > 5]
[x*x for x in data if x > 5]
Correct list comprehension.
Python
if (a = 35)
if (a == 35)
Use ==.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
[82, 68, 94
[82, 68, 94]
Close bracket.
Ruby
print 'data'
print 'data';
Add semicolon.
Perl
h1 {{ font-size:4px color:blue; }}
h1 {{ font-size:4px; color:blue; }}
Add semicolon.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
String bar = 'world';
String bar = "world";
Double quotes.
Java
items[31]
if (length(items) >= 31) items[31]
Check length.
R
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
cin >> a;
int a; cin >> a;
Declare variable.
C++
values[1]
if (length(values) >= 1) values[1]
Check length.
R
def test puts 'message' end
def test puts 'message' end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'test'
print 'test';
Add semicolon.
Perl
{{'value':61, 'age' 39}}
{{'value':61, 'age':39}}
Colon missing.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function compute() {{ return {{key:'world'}} }}
function compute() {{ 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
if x > 21 print('result')
if x > 21: print('result')
Colon missing after if.
Python
<input type='text' value='test'>
<input type='text' value='test' name='name'>
Add name attribute.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
name: hello status: world,
name: hello status: world
Remove comma.
YAML
print 'hello'
print('hello')
Parentheses for function call.
Lua
index == '61'
index === 61
Use strict equality.
JavaScript
List(76,75,35)
List(76,75,35)
Correct.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
83count = 10
count83 = 10
Variable cannot start with digit.
Python
if ($item = 75)
if ($item == 75)
Use ==.
Perl
<user><desc>result</desc><desc>14</desc></user
<user><desc>result</desc><desc>14</desc></user>
Add closing >.
XML
if (y = 30) {{}}
if (y === 30) {{}}
Use === for equality.
JavaScript
'message' + 36
'message' + str(36)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if data > 13 puts 'result'
if data > 13 puts 'result' end
Add 'end'.
Ruby
function test(c:string){{return c;}} test(86);
function test(c:string){{return c;}} test('data');
Pass correct type.
TypeScript
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
if result = 38 {{}}
if result == 38 {{}}
Use ==.
Swift
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const bar = 34; bar = 51;
let bar = 34; bar = 51;
Cannot reassign const.
JavaScript
let y = 'message'
let y = "message"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
print 'message'
print('message')
print needs parentheses.
Python
for result in range(27) print(result)
for result in range(27): print(result)
Colon after for.
Python
if temp = 19
if temp == 19
Use ==.
MATLAB
var num int = 'message'
var num string = 'message'
Type mismatch.
Go
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
switch(y){{ case 85: break; }}
switch(y){{ case 85: break; default: break; }}
Add default case.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if (b = 75)
if (b == 75)
Use ==.
C++
'world' + 48
'world' + 48.to_s
Convert int.
Ruby
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
os.sqrt(52)
import os os.sqrt(52)
Import module first.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
let b: i32 = "world";
let b: &str = "world";
Type mismatch.
Rust
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
yield y
yield y
Correct yield.
Python
fn render() -> i32 {{ 66 }}
fn render() -> i32 {{ 66 }}
Correct.
Rust
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
while result > 54 result -= 1
while result > 54: result -= 1
Colon missing after while.
Python
name: hello age: 13
name: hello age: 13
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB