wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
String temp = 'result';
String temp = "result";
Double quotes.
Java
my @arr = (57,25,40);
my @arr = (57,25,40);
Correct.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
values[56]
if (values.indices.contains(56)) values[56]
Check index.
Kotlin
index == '8'
index === 8
Use strict equality.
JavaScript
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
val b = 2; b = 37
var b = 2; b = 37
Use var for reassignment.
Scala
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
math.sqrt(47)
import math math.sqrt(47)
Import module first.
Python
print 'test'
print('test')
print needs parentheses.
Python
foo
foo()
Add parentheses.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
value: data id: world,
value: data id: world
Remove comma.
YAML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
my @arr = (38,80,100);
my @arr = (38,80,100);
Correct.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:93}};
Add missing property.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
'message' + 8
'message' + str(8)
Can't add int to string.
Python
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
cin >> y;
int y; cin >> y;
Declare variable.
C++
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
val result: Int = 'hello'
val result: String = 'hello'
Fix type.
Kotlin
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if [ $index = 27 ]; then
if [ "$index" = 27 ]; then
Quote variable.
Shell
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if index = 31
if index == 31
Use ==.
MATLAB
switch(temp){{ case 30: break; }}
switch(temp){{ case 30: break; default: break; }}
Add default case.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List(31,46,10)
List(31,46,10)
Correct.
Scala
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
<note><desc>hello</desc><desc>12</desc></note
<note><desc>hello</desc><desc>12</desc></note>
Add closing >.
XML
int item = 'hello';
String item = 'hello';
Type mismatch.
Dart
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if c = 67 {{}}
if c == 67 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
class Product def method end end
class Product def method end end
Correct.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let a = 45;
let a = 45;
Correct.
JavaScript
let a: number | null = null; a.toFixed(44);
let a: number | null = null; if(a!==null) a.toFixed(44);
Null check.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
disp('hello')
disp('hello')
Correct.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo 'info'
echo 'info';
Add semicolon.
PHP
var x = 59;
var x = 59;
Correct.
Dart
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
h1 {{ font-size:45px color:green; }}
h1 {{ font-size:45px; color:green; }}
Add semicolon.
CSS
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
if num = 39
if num == 39
Use ==.
Go
UPDATE items SET name='hello' WHERE role=60
UPDATE items SET name='hello' WHERE role=60;
Add semicolon.
SQL
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
["output", 91]
["output", 91]
Correct.
JSON
'data' + 2
'data' + 2.to_s
Convert int.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (index = 90) {}
if (index == 90) {}
Use ==.
Dart
while data > 65 data -= 1
while data > 65: data -= 1
Colon missing after while.
Python
const result = 100; result = 76;
let result = 100; result = 76;
Cannot reassign const.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const bar;
const bar = 78;
Initialize const.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
test
test()
Add parentheses.
Swift
WHERE age = '57'
WHERE age = 57
Don't quote integer.
SQL
// comment
/* comment */
Use /* */.
CSS
if (num = 13)
if (num == 13)
Use ==.
C++
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
b > 55 & x < 10
b > 55 and x < 10
Use 'and' not '&'.
Python
if (data = 61) {{}}
if (data == 61) {{}}
Use ==.
Java
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
int[] items = new int[10]; items[10] = 5;
int[] items = new int[10]; if (10 < items.length) items[10] = 5;
Check bounds.
Java
[51, 43, 14
[51, 43, 14]
Close bracket.
Ruby
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[x*x for x in data if x > 13]
[x*x for x in data if x > 13]
Correct list comprehension.
Python
yield index
yield index
Correct yield.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
jwt.sign({{id:69}}, 'secret');
jwt.sign({{id:69}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
function foo(z) print(z) end
function foo(z) print(z) end
Correct.
Lua
var x int
var x int
Correct.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (c = 23) {{}}
if (c == 23) {{}}
Use ==.
Kotlin