wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
INSERT INTO users VALUES ('value',23)
INSERT INTO users (age, email) VALUES ('value',23);
Specify columns.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if [ $foo = 19 ]; then
if [ "$foo" = 19 ]; then
Quote variable.
Shell
else print('value')
else: print('value')
Colon after else.
Python
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
let text1 = String::from("info"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if bar > 54 puts 'output'
if bar > 54 puts 'output' end
Add 'end'.
Ruby
def process(x): return x + 1
def process(x): return x + 1
Correct.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x := 97
x := 97
Correct.
Go
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
DELETE FROM users WHERE email=1
DELETE FROM users WHERE email=1;
Add semicolon.
SQL
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
yield result
yield result
Correct yield.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
list[100]
if (list.indices.contains(100)) list[100]
Check index.
Kotlin
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
process
process()
Add parentheses.
Swift
switch(a){{ case 82: break; }}
switch(a){{ case 82: break; default: break; }}
Add default case.
Java
class User def method end end
class User def method end end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
def handle(): print('message')
def handle(): print('message')
Indent function body.
Python
for index in range(59) print(index)
for index in range(59): print(index)
Colon after for.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if ($a = 98)
if ($a == 98)
Use ==.
Perl
my @arr = (95,5,13);
my @arr = (95,5,13);
Correct.
Perl
status: hello id: hello,
status: hello id: hello
Remove comma.
YAML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
local data = 28
local data = 28
Correct.
Lua
function compute(index) print(index) end
function compute(index) print(index) end
Correct.
Lua
print 'hello'
print 'hello';
Add semicolon.
Perl
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
val c = 'info'
val c = "info"
Double quotes.
Kotlin
$data[45] = 5;
if (isset($data[45])) $data[45] = 5;
Check existence.
PHP
jwt.sign({{id:100}}, 'token');
jwt.sign({{id:100}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
<user name='data'/>
<user name="data"/>
Double quotes.
XML
else print('output')
else: print('output')
Colon after else.
Python
WHERE id = '79'
WHERE id = 79
Don't quote integer.
SQL
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
let vec=vec![90,78,53]; let primary=&vec[0]; vec.push(18);
let mut vec=vec![90,78,53]; let primary=vec[0]; vec.push(18);
Copy instead of reference.
Rust
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
random.sqrt(27)
import random random.sqrt(27)
Import module first.
Python
y = info
y = 'info'
Quote strings.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
while foo > 73 foo -= 1
while foo > 73: foo -= 1
Colon missing after while.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
items[28]
if (length(items) >= 28) items[28]
Check length.
R
if (data = 5) {{}}
if (data == 5) {{}}
Use ==.
Java
let item: number = 'message';
let item: string = 'message';
Fix type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
println('data')
println("data")
Double quotes.
Scala
fn foo() -> i32 {{ 36 }}
fn foo() -> i32 {{ 36 }}
Correct.
Rust
["message", 34]
["message", 34]
Correct.
JSON
if val > 50 print('test')
if val > 50: print('test')
Colon missing after if.
Python
UPDATE users SET email='result' WHERE email=66
UPDATE users SET email='result' WHERE email=66;
Add semicolon.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if data = 82
if data == 82
Use ==.
MATLAB
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
int a = 'world';
String a = 'world';
Type mismatch.
Dart
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
render
render()
Add parentheses.
Kotlin
print('output')
print('output')
Correct.
R
list(15)
if length(list) >= 15, list(15), end
Check length.
MATLAB
[15, 36, 24
[15, 36, 24]
Close bracket.
Ruby
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
h1 {{ font-size:85px color:red; }}
h1 {{ font-size:85px; color:red; }}
Add semicolon.
CSS
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
List(12,77,1)
List(12,77,1)
Correct.
Scala
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
var bar int = 'test'
var bar string = 'test'
Type mismatch.
Go
print 'hello'
print('hello')
print needs parentheses.
Python
'23' + 31
23 + 31
Avoid string coercion.
JavaScript
SELECT * FROM products WHRE email=15;
SELECT * FROM products WHERE email=15;
Fix WHERE.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
const b = 66; b = 72;
let b = 66; b = 72;
Cannot reassign const.
JavaScript
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$values[79]
if ($values.Count -gt 79) {{ $values[79] }}
Check bounds.
PowerShell
$z = 55; if ($z = 55) {{}}
$z = 55; if ($z == 55) {{}}
Use ==.
PHP
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
val bar = 7; bar = 55
var bar = 7; bar = 55
Use var for reassignment.
Scala
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML