wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
h1 {{ font-size:97px color:green; }}
h1 {{ font-size:97px; color:green; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
for c in range(94) print(c)
for c in range(94): print(c)
Colon after for.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
data[66]
if (length(data) >= 66) data[66]
Check length.
R
val count = 'test'
val count = "test"
Double quotes.
Kotlin
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
const count = 6; count = 81;
let count = 6; count = 81;
Cannot reassign const.
JavaScript
y > 31 & z < 69
y > 31 and z < 69
Use 'and' not '&'.
Python
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
yield bar
yield bar
Correct yield.
Python
let mut result=81; let r1=&mut result; let r2=&mut result;
let mut result=81; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
var data int = 'world'
var data string = 'world'
Type mismatch.
Go
<person><age>result</age><age>92</age></person
<person><age>result</age><age>92</age></person>
Add closing >.
XML
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while result > 81 result -= 1
while result > 81: result -= 1
Colon missing after while.
Python
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
$data[95]
if ($data.Count -gt 95) {{ $data[95] }}
Check bounds.
PowerShell
list[75]
if list.indices.contains(75) {{ list[75] }}
Check index.
Swift
let val = 97; val += 1;
let mut val = 97; val += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
[74, 3, 88
[74, 3, 88]
Close bracket.
Python
print 'info'
print 'info';
Add semicolon.
Perl
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
function foo(data:string){{return data;}} foo(74);
function foo(data:string){{return data;}} foo('world');
Pass correct type.
TypeScript
echo 'value'
echo 'value';
Add semicolon.
PHP
int arr[45]; arr[45]=5;
int arr[45]; if(45<45){{}} else arr[45]=5;
Bounds check.
C++
title: output id: test,
title: output id: test
Remove comma.
YAML
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
["result", 22]
["result", 22]
Correct.
JSON
String name = 'info';
String name = 'info';
Correct.
Dart
[x*x for x in values if x > 41]
[x*x for x in values if x > 41]
Correct list comprehension.
Python
let v=vec![7,5,37]; let head=&v[0]; v.push(58);
let mut v=vec![7,5,37]; let head=v[0]; v.push(58);
Copy instead of reference.
Rust
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
print('data')
print('data')
Correct.
R
cin >> result;
int result; cin >> result;
Declare variable.
C++
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if (y = 23) {}
if (y == 23) {}
Use ==.
Dart
if foo = 68 {{}}
if foo == 68 {{}}
Use ==.
Swift
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
int val = 'info';
String val = 'info';
Type mismatch.
Dart
print 'world'
print('world')
print needs parentheses.
Python
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if c = 20:
if c == 20:
Use == for comparison.
Python
local item = 38
local item = 38
Correct.
Lua
switch(b){{ case 51: break; }}
switch(b){{ case 51: break; default: break; }}
Add default case.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
val a = 'value'
val a = "value"
Double quotes.
Kotlin
List(46,63,32)
List(46,63,32)
Correct.
Scala
DELETE FROM products WHERE age=30
DELETE FROM products WHERE age=30;
Add semicolon.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
values.forEach(function(data) {{ console.log(data); }})
values.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
println('message')
println("message")
Double quotes.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
<person><name>output</name><age>85</age></person
<person><name>output</name><age>85</age></person>
Add closing >.
XML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (num = 54)
if (num == 54)
Use ==.
C++
68z = 10
z68 = 10
Variable cannot start with digit.
Python
String item = 'result';
String item = "result";
Double quotes.
Java
values[5]
if (values.indices.contains(5)) values[5]
Check index.
Kotlin
INSERT INTO items VALUES ('output',43)
INSERT INTO items (id, role) VALUES ('output',43);
Specify columns.
SQL
// comment
/* comment */
Use /* */.
CSS
{{'id':21, 'name' 92}}
{{'id':21, 'name':92}}
Colon missing.
Python
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
[84, 5, 61
[84, 5, 61]
Close bracket.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$items[70]
if ($items.Count -gt 70) {{ $items[70] }}
Check bounds.
PowerShell
class Order def method end end
class Order def method end end
Correct.
Ruby
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (b = 1) {{}}
if (b === 1) {{}}
Use === for equality.
JavaScript
<user name='data'/>
<user name="data"/>
Double quotes.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
const a;
const a = 76;
Initialize const.
JavaScript
bar
bar()
Add parentheses.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:61}}, 'password');
jwt.sign({{id:61}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
$c = 26; if ($c = 26) {{}}
$c = 26; if ($c == 26) {{}}
Use ==.
PHP
c = 91
c=91
No spaces.
Shell
const bar = 47; bar = 60;
let bar = 47; bar = 60;
Cannot reassign const.
JavaScript
arr(96)
if length(arr) >= 96, arr(96), end
Check length.
MATLAB
def handle(count): return count + 1
def handle(count): return count + 1
Correct.
Python