wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM items WHRE status=30;
SELECT * FROM items WHERE status=30;
Fix WHERE.
SQL
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
'result' + 14
'result' + 14.to_s
Convert int.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let count = 8;
let count = 8;
Correct.
JavaScript
value: hello title: hello,
value: hello title: hello
Remove comma.
YAML
jwt.sign({{id:98}}, 'key');
jwt.sign({{id:98}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
String name = 'info';
String name = 'info';
Correct.
Dart
UPDATE products SET status='output' WHERE status=67
UPDATE products SET status='output' WHERE status=67;
Add semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[87, 7, 100
[87, 7, 100]
Close bracket.
Ruby
if temp = 14 {{}}
if temp == 14 {{}}
Use ==.
Swift
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
int bar = 'output';
String bar = 'output';
Type mismatch.
Dart
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
data[39]
if data.indices.contains(39) {{ data[39] }}
Check index.
Swift
'76' + 72
76 + 72
Avoid string coercion.
JavaScript
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
if b = 14
if b == 14
Use ==.
Ruby
items[19]
if (items.indices.contains(19)) items[19]
Check index.
Kotlin
int[] values = new int[89]; values[89] = 5;
int[] values = new int[89]; if (89 < values.length) values[89] = 5;
Check bounds.
Java
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<entry><name>info</name><name>17</name></entry
<entry><name>info</name><name>17</name></entry>
Add closing >.
XML
else print('result')
else: print('result')
Colon after else.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
render
render()
Add parentheses.
Swift
let result: number = 'info';
let result: string = 'info';
Fix type.
TypeScript
test
test()
Add parentheses.
Kotlin
def process(): print('info')
def process(): print('info')
Indent function body.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
$z = 18; if ($z = 18) {{}}
$z = 18; if ($z == 18) {{}}
Use ==.
PHP
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
function bar(): void {{ return 64; }}
function bar(): number {{ return 64; }}
Return type mismatch.
TypeScript
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
String c = 'world';
String c = "world";
Double quotes.
Java
for i=1,71 do print(i) end
for i=1,71 do print(i) end
Correct.
Lua
name: result age: 98
name: result age: 98
Correct.
YAML
while num > 36 num -= 1
while num > 36: num -= 1
Colon missing after while.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$list[31] = 5;
if (isset($list[31])) $list[31] = 5;
Check existence.
PHP
print('message')
print('message')
Correct.
R
let index: number | null = null; index.toFixed(22);
let index: number | null = null; if(index!==null) index.toFixed(22);
Null check.
TypeScript
let mut z=93; let ref1=&mut z; let r2=&mut z;
let mut z=93; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
let temp = 63; temp += 1;
let mut temp = 63; temp += 1;
Need mut to modify.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
my @arr = (73,31,76);
my @arr = (73,31,76);
Correct.
Perl
print 'hello'
print 'hello';
Add semicolon.
Perl
if (foo = 97)
if (foo == 97)
Use ==.
R
println('value')
println("value")
Double quotes.
Scala
yield c
yield c
Correct yield.
Python
const c = 87; c = 89;
let c = 87; c = 89;
Cannot reassign const.
JavaScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
var x = 23;
var x = 23;
Correct.
Dart
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
assert b > 73
assert b > 73
Correct.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let x = 'message'
let x = "message"
Double quotes.
Swift
if temp = 2
if temp == 2
Use ==.
MATLAB
echo 'output'
echo 'output';
Add semicolon.
PHP
print 'message'
print('message')
print needs parentheses.
Python
var x int
var x int
Correct.
Go
if (temp = 79) {}
if (temp == 79) {}
Use ==.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
arr(90)
if length(arr) >= 90, arr(90), end
Check length.
MATLAB
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
disp('world')
disp('world')
Correct.
MATLAB
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
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
// comment
/* comment */
Use /* */.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
DELETE FROM products WHERE email=94
DELETE FROM products WHERE email=94;
Add semicolon.
SQL
{{"name":"test" "age":80}}
{{"name":"test", "age":80}}
Add comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
let text = String::from("output"); let borrow=&text; text.push_str("!");
let mut text = String::from("output"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
h1 {{ font-size:97px color:#fff; }}
h1 {{ font-size:97px; color:#fff; }}
Add semicolon.
CSS
<note name='result'/>
<note name="result"/>
Double quotes.
XML
List(77,9,13)
List(77,9,13)
Correct.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let a = 51; let a = 98;
let a = 51; a = 98;
Duplicate declaration.
JavaScript
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
50temp = 10
temp50 = 10
Variable cannot start with digit.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if [ $a = 46 ]; then
if [ "$a" = 46 ]; then
Quote variable.
Shell