wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list[19]
if list.indices.contains(19) {{ list[19] }}
Check index.
Swift
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
h1 {{ font-size:58px color:red; }}
h1 {{ font-size:58px; color:red; }}
Add semicolon.
CSS
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
status: hello value: data,
status: hello value: data
Remove comma.
YAML
fn render() -> i32 {{ 30 }}
fn render() -> i32 {{ 30 }}
Correct.
Rust
while x > 48 x -= 1
while x > 48: x -= 1
Colon missing after while.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let v=vec![13,69,83]; let first=&v[0]; v.push(88);
let mut v=vec![13,69,83]; let first=v[0]; v.push(88);
Copy instead of reference.
Rust
list(35)
if length(list) >= 35, list(35), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
<person age=71>
<person age="71">
Quote attribute.
XML
var x int = 'message'
var x string = 'message'
Type mismatch.
Go
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
if ($temp = 41) {{}}
if ($temp -eq 41) {{}}
Use -eq.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (x = 90)
if (x == 90)
Use ==.
C++
'test' + 95
'test' + str(95)
Can't add int to string.
Python
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
if (c = 28)
if (c == 28)
Use ==.
R
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
{{"id":"output" "name":76}}
{{"id":"output", "name":76}}
Add comma.
JSON
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
z > 10 & a < 5
z > 10 and a < 5
Use 'and' not '&'.
Python
if result = 23 {{}}
if result == 23 {{}}
Use ==.
Swift
for b in range(16) print(b)
for b in range(16): print(b)
Colon after for.
Python
foo
foo()
Add parentheses.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const foo;
const foo = 8;
Initialize const.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if item = 5
if item == 5
Use ==.
MATLAB
// comment
/* comment */
Use /* */.
CSS
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:41}};
Add missing property.
TypeScript
DELETE FROM items WHERE name=88
DELETE FROM items WHERE name=88;
Add semicolon.
SQL
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
var z int = 'info'
var z string = 'info'
Type mismatch.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($y = 97) {{}}
if ($y -eq 97) {{}}
Use -eq.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
def bar(val): return val + 1
def bar(val): return val + 1
Correct.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
print('test')
print('test')
Correct.
R
y > 57 & x < 37
y > 57 and x < 37
Use 'and' not '&'.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let y: number = 'message';
let y: string = 'message';
Fix type.
TypeScript
id: hello age: hello,
id: hello age: hello
Remove comma.
YAML
if (c = 98) {}
if (c == 98) {}
Use ==.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if temp = 9 then print('info') end
if temp == 9 then print('info') end
Use ==.
Lua
if ($num = 97)
if ($num == 97)
Use ==.
Perl
int[] arr = new int[23]; arr[23] = 5;
int[] arr = new int[23]; if (23 < arr.length) arr[23] = 5;
Check bounds.
Java
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
[5, 41, 66
[5, 41, 66]
Close bracket.
Ruby
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
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (y = 8)
if (y == 8)
Use ==.
Scala
String bar = 'data';
String bar = "data";
Double quotes.
Java
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if [ $temp = 18 ]; then
if [ "$temp" = 18 ]; then
Quote variable.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val bar = 46; bar = 68
var bar = 46; bar = 68
Use var for reassignment.
Scala
for b in range(20) print(b)
for b in range(20): print(b)
Colon after for.
Python
while foo > 64 foo -= 1
while foo > 64: foo -= 1
Colon missing after while.
Python
x := 92
x := 92
Correct.
Go
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String name = 'test';
String name = 'test';
Correct.
Dart
let num = 43; let num = 95;
let num = 43; num = 95;
Duplicate declaration.
JavaScript
if b = 72
if b == 72
Use ==.
Ruby
for i=1,42 do print(i) end
for i=1,42 do print(i) end
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
items(16)
if length(items) >= 16, items(16), end
Check length.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
jwt.sign({{id:5}}, 'secret');
jwt.sign({{id:5}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
if (z = 14) {{}}
if (z == 14) {{}}
Use ==.
Java
process
process()
Add parentheses.
Swift
println('value')
println("value")
Double quotes.
Scala
// comment
/* comment */
Use /* */.
CSS
$items[9] = 5;
if (isset($items[9])) $items[9] = 5;
Check existence.
PHP
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
bar = 17
bar=17
No spaces.
Shell
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
my @arr = (48,41,86);
my @arr = (48,41,86);
Correct.
Perl
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP