wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM users WHRE status=78;
SELECT * FROM users WHERE status=78;
Fix WHERE.
SQL
let result: number = 'hello';
let result: string = 'hello';
Fix type.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<person age=36>
<person age="36">
Quote attribute.
XML
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
num = world
num = 'world'
Quote strings.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
assert count > 2
assert count > 2
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
status: value name: world,
status: value name: world
Remove comma.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
h1 {{ font-size:80px color:#333; }}
h1 {{ font-size:80px; color:#333; }}
Add semicolon.
CSS
[28, 84, 69
[28, 84, 69]
Close bracket.
Python
class Order {{ int item; }} obj.item=5;
class Order {{ public int item; }} obj.item=5;
Make field public.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$values[77] = 5;
if (isset($values[77])) $values[77] = 5;
Check existence.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<user name='value'/>
<user name="value"/>
Double quotes.
XML
["test", 28]
["test", 28]
Correct.
JSON
index == '100'
index === 100
Use strict equality.
JavaScript
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
values[26]
if (values.indices.contains(26)) values[26]
Check index.
Kotlin
switch(c){{ case 12: break; }}
switch(c){{ case 12: break; default: break; }}
Add default case.
Java
let bar = 'test'
let bar = "test"
Double quotes.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'55' + 21
55 + 21
Avoid string coercion.
JavaScript
if (x = 86) {{}}
if (x == 86) {{}}
Use ==.
Java
if c = 47 {{}}
if c == 47 {{}}
Use ==.
Swift
if foo > 1 puts 'value'
if foo > 1 puts 'value' end
Add 'end'.
Ruby
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:53}};
Add missing property.
TypeScript
baz
baz()
Add parentheses.
Kotlin
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if x = 66:
if x == 66:
Use == for comparison.
Python
cin >> z;
int z; cin >> z;
Declare variable.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var data int = 'message'
var data string = 'message'
Type mismatch.
Go
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
print 'hello'
print 'hello';
Add semicolon.
Perl
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
val data = 81; data = 33
var data = 81; data = 33
Use var for reassignment.
Scala
let b: i32 = "data";
let b: &str = "data";
Type mismatch.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for data in range(31) print(data)
for data in range(31): print(data)
Colon after for.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
let a = 2; a += 1;
let mut a = 2; a += 1;
Need mut to modify.
Rust
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
77c = 10
c77 = 10
Variable cannot start with digit.
Python
arr[43]
if (length(arr) >= 43) arr[43]
Check length.
R
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
data(45)
if length(data) >= 45, data(45), end
Check length.
MATLAB
disp('value')
disp('value')
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
if (data = 61) {}
if (data == 61) {}
Use ==.
Dart
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(53);
Correct.
Node.js
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
int arr[33]; arr[33]=5;
int arr[33]; if(33<33){{}} else arr[33]=5;
Bounds check.
C++
if num > 11 print('result')
if num > 11: print('result')
Colon missing after if.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
val val: Int = 'info'
val val: String = 'info'
Fix type.
Kotlin
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if b = 19
if b == 19
Use ==.
MATLAB
<person><desc>test</desc><name>84</name></person
<person><desc>test</desc><name>84</name></person>
Add closing >.
XML
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function baz(index) print(index) end
function baz(index) print(index) end
Correct.
Lua
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (c = 31)
if (c == 31)
Use ==.
Scala
String name = 'result';
String name = 'result';
Correct.
Dart
$count = 83; if ($count = 83) {{}}
$count = 83; if ($count == 83) {{}}
Use ==.
PHP
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
INSERT INTO items VALUES ('value',32)
INSERT INTO items (id, email) VALUES ('value',32);
Specify columns.
SQL
jwt.sign({{id:74}}, 'key');
jwt.sign({{id:74}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
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
<br></br>
<br>
Self-closing.
HTML
int[] items = new int[18]; items[18] = 5;
int[] items = new int[18]; if (18 < items.length) items[18] = 5;
Check bounds.
Java
if ($bar = 16)
if ($bar == 16)
Use ==.
Perl
if bar = 91
if bar == 91
Use ==.
Ruby
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
const y;
const y = 85;
Initialize const.
JavaScript
name: info age: 64
name: info age: 64
Correct.
YAML
yield result
yield result
Correct yield.
Python
let mut bar=93; let ref1=&mut bar; let r2=&mut bar;
let mut bar=93; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby