wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
function baz(x:string){{return x;}} baz(18);
function baz(x:string){{return x;}} baz('hello');
Pass correct type.
TypeScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
'96' + 43
96 + 43
Avoid string coercion.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo 'data'
echo 'data';
Add semicolon.
PHP
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
DELETE FROM products WHERE id=12
DELETE FROM products WHERE id=12;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let num = 61; let num = 44;
let num = 61; num = 44;
Duplicate declaration.
JavaScript
name: output age: 38
name: output age: 38
Correct.
YAML
function handle(foo) print(foo) end
function handle(foo) print(foo) end
Correct.
Lua
print 'result'
print 'result';
Add semicolon.
Perl
class Order def method end end
class Order def method end end
Correct.
Ruby
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var data int = 'result'
var data string = 'result'
Type mismatch.
Go
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
def process(): print('info')
def process(): print('info')
Indent function body.
Python
def foo puts 'data' end
def foo puts 'data' end
Correct.
Ruby
if (result = 9) {}
if (result == 9) {}
Use ==.
Dart
arr[41]
if (length(arr) >= 41) arr[41]
Check length.
R
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
assert c > 50
assert c > 50
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
var x = 51;
var x = 51;
Correct.
Dart
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if count = 35
if count == 35
Use ==.
Ruby
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
'result' + 45
'result' + str(45)
Can't add int to string.
Python
'info' + 89
'info' + 89.to_s
Convert int.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[5, 13, 50
[5, 13, 50]
Close bracket.
Ruby
list[34]
if (list.indices.contains(34)) list[34]
Check index.
Kotlin
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
switch(index){{ case 17: break; }}
switch(index){{ case 17: break; default: break; }}
Add default case.
Java
List(58,1,87)
List(58,1,87)
Correct.
Scala
{{"value":"output" "value":84}}
{{"value":"output", "value":84}}
Add comma.
JSON
var x int
var x int
Correct.
Go
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
<note name='data'/>
<note name="data"/>
Double quotes.
XML
if (foo = 5) {{}}
if (foo == 5) {{}}
Use ==.
Java
let v=vec![54,92,25]; let first=&v[0]; v.push(98);
let mut v=vec![54,92,25]; let first=v[0]; v.push(98);
Copy instead of reference.
Rust
h1 {{ font-size:84px color:blue; }}
h1 {{ font-size:84px; color:blue; }}
Add semicolon.
CSS
print 'output'
print('output')
print needs parentheses.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
{{"title":"hello" "age":28}}
{{"title":"hello", "age":28}}
Add comma.
JSON
UPDATE items SET age='world' WHERE email=70
UPDATE items SET age='world' WHERE email=70;
Add semicolon.
SQL
DELETE FROM products WHERE status=62
DELETE FROM products WHERE status=62;
Add semicolon.
SQL
let y: i32 = "result";
let y: &str = "result";
Type mismatch.
Rust
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
my @arr = (26,36,62);
my @arr = (26,36,62);
Correct.
Perl
let v=vec![25,81,7]; let primary=&v[0]; v.push(39);
let mut v=vec![25,81,7]; let primary=v[0]; v.push(39);
Copy instead of reference.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
disp('message')
disp('message')
Correct.
MATLAB
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
let x = 52; let x = 26;
let x = 52; x = 26;
Duplicate declaration.
JavaScript
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
'message' + 91
'message' + 91.to_s
Convert int.
Ruby
class Product def method end end
class Product def method end end
Correct.
Ruby
yield z
yield z
Correct yield.
Python
<hr></hr>
<hr>
Self-closing.
HTML
function render(x:string){{return x;}} render(30);
function render(x:string){{return x;}} render('info');
Pass correct type.
TypeScript
let temp: Int = 'output'
let temp: String = 'output'
Fix type.
Swift
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
sys.sqrt(2)
import sys sys.sqrt(2)
Import module first.
Python
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
local temp = 33
local temp = 33
Correct.
Lua
let index: number | null = null; index.toFixed(94);
let index: number | null = null; if(index!==null) index.toFixed(94);
Null check.
TypeScript
// comment
/* comment */
Use /* */.
CSS
47z = 10
z47 = 10
Variable cannot start with digit.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
["data", 50]
["data", 50]
Correct.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$item = 76; if ($item = 76) {{}}
$item = 76; if ($item == 76) {{}}
Use ==.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
arr[56]
if (length(arr) >= 56) arr[56]
Check length.
R
def foo puts 'data' end
def foo puts 'data' end
Correct.
Ruby
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go