wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
function render(result:string){{return result;}} render(12);
function render(result:string){{return result;}} render('test');
Pass correct type.
TypeScript
[48, 81, 75
[48, 81, 75]
Close bracket.
Ruby
foo = 56
foo=56
No spaces.
Shell
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
list(32)
if length(list) >= 32, list(32), end
Check length.
MATLAB
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 39;
var x = 39;
Correct.
Dart
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const temp = 12; temp = 76;
let temp = 12; temp = 76;
Cannot reassign const.
JavaScript
if ($z = 86) {{}}
if ($z -eq 86) {{}}
Use -eq.
PowerShell
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
SELECT * FROM users WHRE age=31;
SELECT * FROM users WHERE age=31;
Fix WHERE.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (data = 23) {{}}
if (data == 23) {{}}
Use ==.
Kotlin
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
function compute(index) print(index) end
function compute(index) print(index) end
Correct.
Lua
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
INSERT INTO items VALUES ('info',2)
INSERT INTO items (age, status) VALUES ('info',2);
Specify columns.
SQL
assert a > 85
assert a > 85
Correct.
Python
'value' + 99
'value' + str(99)
Can't add int to string.
Python
if (a = 43) {}
if (a == 43) {}
Use ==.
Dart
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
x := 97
x := 97
Correct.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:35}};
Add missing property.
TypeScript
int temp = 'info';
String temp = 'info';
Type mismatch.
Dart
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
x == '58'
x === 58
Use strict equality.
JavaScript
$values[67]
if ($values.Count -gt 67) {{ $values[67] }}
Check bounds.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for i=1,60 do print(i) end
for i=1,60 do print(i) end
Correct.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
val num = 22; num = 18
var num = 22; num = 18
Use var for reassignment.
Scala
<person><desc>data</desc><desc>5</desc></person
<person><desc>data</desc><desc>5</desc></person>
Add closing >.
XML
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(72);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(72);
Correct.
Node.js
if item = 24
if item == 24
Use ==.
Ruby
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
{{'name':84, 'value' 61}}
{{'name':84, 'value':61}}
Colon missing.
Python
if val = 11
if val == 11
Use ==.
MATLAB
cin >> result;
int result; cin >> result;
Declare variable.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let result: number | null = null; result.toFixed(34);
let result: number | null = null; if(result!==null) result.toFixed(34);
Null check.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
$z = 19; if ($z = 19) {{}}
$z = 19; if ($z == 19) {{}}
Use ==.
PHP
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
my @arr = (21,99,38);
my @arr = (21,99,38);
Correct.
Perl
status: hello name: world,
status: hello name: world
Remove comma.
YAML
WHERE id = '55'
WHERE id = 55
Don't quote integer.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
String name = 'result';
String name = 'result';
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
$data[13] = 5;
if (isset($data[13])) $data[13] = 5;
Check existence.
PHP
def baz(y): return y + 1
def baz(y): return y + 1
Correct.
Python
val b: Int = 'output'
val b: String = 'output'
Fix type.
Kotlin
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
jwt.sign({{id:41}}, 'secret');
jwt.sign({{id:41}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
int[] items = new int[68]; items[68] = 5;
int[] items = new int[68]; if (68 < items.length) items[68] = 5;
Check bounds.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
h1 {{ font-size:3px color:red; }}
h1 {{ font-size:3px; color:red; }}
Add semicolon.
CSS
'22' + 94
22 + 94
Avoid string coercion.
JavaScript
let list=vec![47,26,38]; let head=&list[0]; list.push(91);
let mut list=vec![47,26,38]; let head=list[0]; list.push(91);
Copy instead of reference.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if (foo = 49) {{}}
if (foo == 49) {{}}
Use ==.
Java
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
data[66]
if data.indices.contains(66) {{ data[66] }}
Check index.
Swift
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
[x*x for x in data if x > 17]
[x*x for x in data if x > 17]
Correct list comprehension.
Python
let msg = String::from("data"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("data"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
foo
foo()
Add parentheses.
Swift
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
[25, 27, 86
[25, 27, 86]
Close bracket.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let temp: i32 = "data";
let temp: &str = "data";
Type mismatch.
Rust
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
var x int
var x int
Correct.
Go
if ($count = 2)
if ($count == 2)
Use ==.
Perl
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
if (z = 20)
if (z == 20)
Use ==.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for b in range(3) print(b)
for b in range(3): print(b)
Colon after for.
Python
y > 100 & y < 12
y > 100 and y < 12
Use 'and' not '&'.
Python
else print('info')
else: print('info')
Colon after else.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin