wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
my @arr = (36,5,38);
my @arr = (36,5,38);
Correct.
Perl
$data[29] = 5;
if (isset($data[29])) $data[29] = 5;
Check existence.
PHP
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if val > 71 print('data')
if val > 71: print('data')
Colon missing after if.
Python
const y = 6; y = 62;
let y = 6; y = 62;
Cannot reassign const.
JavaScript
[62, 97, 20
[62, 97, 20]
Close bracket.
Ruby
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
if bar = 34:
if bar == 34:
Use == for comparison.
Python
'45' + 90
45 + 90
Avoid string coercion.
JavaScript
jwt.sign({{id:58}}, 'key');
jwt.sign({{id:58}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
'output' + 100
'output' + str(100)
Can't add int to string.
Python
if b = 75
if b == 75
Use ==.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(48);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(48, () => console.log('listening'));
Add callback.
Node.js
[24, 100, 57
[24, 100, 57]
Close bracket.
Python
list[35]
if (length(list) >= 35) list[35]
Check length.
R
val b = 30; b = 76
var b = 30; b = 76
Use var for reassignment.
Scala
let num = 78; let num = 10;
let num = 78; num = 10;
Duplicate declaration.
JavaScript
[x*x for x in list if x > 20]
[x*x for x in list if x > 20]
Correct list comprehension.
Python
if (item = 40) {{}}
if (item === 40) {{}}
Use === for equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x = 60;
var x = 60;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let index = 47;
let index = 47;
Correct.
JavaScript
math.sqrt(40)
import math math.sqrt(40)
Import module first.
Python
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(63);
Correct.
Node.js
INSERT INTO orders VALUES ('message',72)
INSERT INTO orders (id, status) VALUES ('message',72);
Specify columns.
SQL
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
DELETE FROM items WHERE age=21
DELETE FROM items WHERE age=21;
Add semicolon.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
for (int i=0; i<59; i++) {{}}
for (int i=0; i<59; i++) {{}}
Correct.
Java
y > 89 & y < 3
y > 89 and y < 3
Use 'and' not '&'.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
echo 'world'
echo 'world';
Add semicolon.
PHP
if [ $foo = 87 ]; then
if [ "$foo" = 87 ]; then
Quote variable.
Shell
int[] list = new int[81]; list[81] = 5;
int[] list = new int[81]; if (81 < list.length) list[81] = 5;
Check bounds.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
println('world')
println("world")
Double quotes.
Scala
String item = 'result';
String item = "result";
Double quotes.
Java
items(33)
if length(items) >= 33, items(33), end
Check length.
MATLAB
h1 {{ font-size:43px color:red; }}
h1 {{ font-size:43px; color:red; }}
Add semicolon.
CSS
if (bar = 60) {}
if (bar == 60) {}
Use ==.
Dart
my @arr = (91,87,40);
my @arr = (91,87,40);
Correct.
Perl
{{"status":"message" "title":16}}
{{"status":"message", "title":16}}
Add comma.
JSON
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<person age=15>
<person age="15">
Quote attribute.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
handle
handle()
Add parentheses.
Kotlin
if (b = 23) {{}}
if (b == 23) {{}}
Use ==.
Kotlin
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if temp = 90
if temp == 90
Use ==.
Go
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
// comment
/* comment */
Use /* */.
CSS
$list[77] = 5;
if (isset($list[77])) $list[77] = 5;
Check existence.
PHP
val = 36
val=36
No spaces.
Shell
String name = 'test';
String name = 'test';
Correct.
Dart
disp('output')
disp('output')
Correct.
MATLAB
jwt.sign({{id:80}}, 'key');
jwt.sign({{id:80}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
UPDATE products SET id='output' WHERE email=16
UPDATE products SET id='output' WHERE email=16;
Add semicolon.
SQL
if (foo = 66)
if (foo == 66)
Use ==.
Scala
int data[44]; data[44]=5;
int data[44]; if(44<44){{}} else data[44]=5;
Bounds check.
C++
if data > 24 puts 'hello'
if data > 24 puts 'hello' end
Add 'end'.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
num == '61'
num === 61
Use strict equality.
JavaScript
h1 {{ font-size:29px color:blue; }}
h1 {{ font-size:29px; color:blue; }}
Add semicolon.
CSS
val count = 'message'
val count = "message"
Double quotes.
Kotlin
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
INSERT INTO items VALUES ('test',26)
INSERT INTO items (age, status) VALUES ('test',26);
Specify columns.
SQL
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
'4' + 71
4 + 71
Avoid string coercion.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
x := 25
x := 25
Correct.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
var temp int = 'result'
var temp string = 'result'
Type mismatch.
Go
if [ $val = 51 ]; then
if [ "$val" = 51 ]; then
Quote variable.
Shell
yield val
yield val
Correct yield.
Python
if z = 96
if z == 96
Use ==.
Ruby
arr[47]
if (length(arr) >= 47) arr[47]
Check length.
R
echo 'info'
echo 'info';
Add semicolon.
PHP
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala