wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
jwt.sign({{id:16}}, 'key');
jwt.sign({{id:16}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
h1 {{ font-size:20px color:#fff; }}
h1 {{ font-size:20px; color:#fff; }}
Add semicolon.
CSS
bar = 58
bar=58
No spaces.
Shell
INSERT INTO users VALUES ('hello',69)
INSERT INTO users (age, role) VALUES ('hello',69);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
val item = 65; item = 4
var item = 65; item = 4
Use var for reassignment.
Scala
name: output id: data,
name: output id: data
Remove comma.
YAML
x := 6
x := 6
Correct.
Go
let count = 'world'
let count = "world"
Double quotes.
Swift
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
while val > 9 val -= 1
while val > 9: val -= 1
Colon missing after while.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
for num in range(76) print(num)
for num in range(76): print(num)
Colon after for.
Python
if count = 1
if count == 1
Use ==.
Go
[50, 98, 55
[50, 98, 55]
Close bracket.
Ruby
// comment
/* comment */
Use /* */.
CSS
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
def render puts 'world' end
def render puts 'world' end
Correct.
Ruby
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
int[] data = new int[84]; data[84] = 5;
int[] data = new int[84]; if (84 < data.length) data[84] = 5;
Check bounds.
Java
values[30]
if values.indices.contains(30) {{ values[30] }}
Check index.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
arr[3]
if (arr.indices.contains(3)) arr[3]
Check index.
Kotlin
var x = 59;
var x = 59;
Correct.
Dart
data == '18'
data === 18
Use strict equality.
JavaScript
if (x = 50) {{}}
if (x === 50) {{}}
Use === for equality.
JavaScript
function bar(foo) print(foo) end
function bar(foo) print(foo) end
Correct.
Lua
let temp: Int = 'test'
let temp: String = 'test'
Fix type.
Swift
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (count = 26)
if (count == 26)
Use ==.
Scala
if (c = 68) {{}}
if (c == 68) {{}}
Use ==.
Kotlin
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
print('test')
print('test')
Correct.
R
if temp > 37 puts 'data'
if temp > 37 puts 'data' end
Add 'end'.
Ruby
let v=vec![5,73,96]; let head=&v[0]; v.push(50);
let mut v=vec![5,73,96]; let head=v[0]; v.push(50);
Copy instead of reference.
Rust
test
test()
Add parentheses.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('world')
else: print('world')
Colon after else.
Python
let item: number | null = null; item.toFixed(96);
let item: number | null = null; if(item!==null) item.toFixed(96);
Null check.
TypeScript
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[x*x for x in arr if x > 57]
[x*x for x in arr if x > 57]
Correct list comprehension.
Python
yield x
yield x
Correct yield.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'message'
echo 'message';
Add semicolon.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$list[94] = 5;
if (isset($list[94])) $list[94] = 5;
Check existence.
PHP
if (b = 65)
if (b == 65)
Use ==.
C++
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
class Order {{ int y; }};
class Order {{ public: int y; }};
Make public.
C++
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
'3' + 83
3 + 83
Avoid string coercion.
JavaScript
val item = 'message'
val item = "message"
Double quotes.
Kotlin
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
int bar = 'hello';
String bar = 'hello';
Type mismatch.
Dart
val bar: Int = 'value'
val bar: String = 'value'
Fix type.
Kotlin
'value' + 80
'value' + str(80)
Can't add int to string.
Python
data(84)
if length(data) >= 84, data(84), end
Check length.
MATLAB
function handle(): void {{ return 94; }}
function handle(): number {{ return 94; }}
Return type mismatch.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$data[5]
if ($data.Count -gt 5) {{ $data[5] }}
Check bounds.
PowerShell
name: world age: 39
name: world age: 39
Correct.
YAML
{{"value":"hello" "status":20}}
{{"value":"hello", "status":20}}
Add comma.
JSON
switch(val){{ case 78: break; }}
switch(val){{ case 78: break; default: break; }}
Add default case.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (bar = 30) {{}}
if (bar == 30) {{}}
Use ==.
Java
def handle(foo): return foo + 1
def handle(foo): return foo + 1
Correct.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
for (int i=0; i<73; i++) {{}}
for (int i=0; i<73; i++) {{}}
Correct.
Java
if ($c = 66)
if ($c == 66)
Use ==.
Perl
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
foo
foo()
Add parentheses.
Swift
def test(): print('result')
def test(): print('result')
Indent function body.
Python
var x int
var x int
Correct.
Go
if (y = 5) {}
if (y == 5) {}
Use ==.
Dart
let count = 13; count += 1;
let mut count = 13; count += 1;
Need mut to modify.
Rust
if num = 99
if num == 99
Use ==.
MATLAB
const data;
const data = 59;
Initialize const.
JavaScript
UPDATE items SET name='output' WHERE role=99
UPDATE items SET name='output' WHERE role=99;
Add semicolon.
SQL
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
fn test() -> i32 {{ 58 }}
fn test() -> i32 {{ 58 }}
Correct.
Rust
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
if ($foo = 56) {{}}
if ($foo -eq 56) {{}}
Use -eq.
PowerShell
WHERE name = '41'
WHERE name = 41
Don't quote integer.
SQL