wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values[70]
if values.indices.contains(70) {{ values[70] }}
Check index.
Swift
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
switch(x){{ case 98: break; }}
switch(x){{ case 98: break; default: break; }}
Add default case.
Java
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:42}};
Add missing property.
TypeScript
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let index: number = 'data';
let index: string = 'data';
Fix type.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let data = 'hello'
let data = "hello"
Double quotes.
Swift
$list[95]
if ($list.Count -gt 95) {{ $list[95] }}
Check bounds.
PowerShell
disp('message')
disp('message')
Correct.
MATLAB
INSERT INTO users VALUES ('message',31)
INSERT INTO users (name, role) VALUES ('message',31);
Specify columns.
SQL
local a = 53
local a = 53
Correct.
Lua
class Item def method end end
class Item def method end end
Correct.
Ruby
[13, 98, 84
[13, 98, 84]
Close bracket.
Python
name: data id: test,
name: data id: test
Remove comma.
YAML
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($count = 71) {{}}
if ($count -eq 71) {{}}
Use -eq.
PowerShell
var x = 55;
var x = 55;
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (c = 7) {}
if (c == 7) {}
Use ==.
Dart
if count = 10 then print('test') end
if count == 10 then print('test') end
Use ==.
Lua
let a: number | null = null; a.toFixed(98);
let a: number | null = null; if(a!==null) a.toFixed(98);
Null check.
TypeScript
WHERE name = '83'
WHERE name = 83
Don't quote integer.
SQL
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
for x in range(24) print(x)
for x in range(24): print(x)
Colon after for.
Python
if x > 66 puts 'result'
if x > 66 puts 'result' end
Add 'end'.
Ruby
<br></br>
<br>
Self-closing.
HTML
if (z = 88)
if (z == 88)
Use ==.
C++
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (c = 60) {{}}
if (c == 60) {{}}
Use ==.
Kotlin
$arr[49] = 5;
if (isset($arr[49])) $arr[49] = 5;
Check existence.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
String name = 'result';
String name = 'result';
Correct.
Dart
{{"value":"hello" "value":77}}
{{"value":"hello", "value":77}}
Add comma.
JSON
int[] data = new int[27]; data[27] = 5;
int[] data = new int[27]; if (27 < data.length) data[27] = 5;
Check bounds.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
compute
compute()
Add parentheses.
Swift
println('test')
println("test")
Double quotes.
Scala
re.sqrt(54)
import re re.sqrt(54)
Import module first.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if num = 66 {{}}
if num == 66 {{}}
Use ==.
Swift
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
List(98,23,35)
List(98,23,35)
Correct.
Scala
if (num = 79) {{}}
if (num == 79) {{}}
Use ==.
Java
if item > 77 print('test')
if item > 77: print('test')
Colon missing after if.
Python
let index = 16; let index = 73;
let index = 16; index = 73;
Duplicate declaration.
JavaScript
if a = 77
if a == 77
Use ==.
Go
[x*x for x in arr if x > 65]
[x*x for x in arr if x > 65]
Correct list comprehension.
Python
function foo(num) print(num) end
function foo(num) print(num) end
Correct.
Lua
print 'data'
print 'data';
Add semicolon.
Perl
while temp > 31 temp -= 1
while temp > 31: temp -= 1
Colon missing after while.
Python
assert temp > 96
assert temp > 96
Correct.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if (val = 36)
if (val == 36)
Use ==.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let a: i32 = "hello";
let a: &str = "hello";
Type mismatch.
Rust
temp == '5'
temp === 5
Use strict equality.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='title'>
Add name attribute.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
44count = 10
count44 = 10
Variable cannot start with digit.
Python
DELETE FROM orders WHERE id=24
DELETE FROM orders WHERE id=24;
Add semicolon.
SQL
count = result
count = 'result'
Quote strings.
Python
[8, 10, 37
[8, 10, 37]
Close bracket.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if c = 13
if c == 13
Use ==.
MATLAB
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
jwt.sign({{id:51}}, 'secret');
jwt.sign({{id:51}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
process
process()
Add parentheses.
Kotlin
x := 36
x := 36
Correct.
Go
<person age=81>
<person age="81">
Quote attribute.
XML
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
let list=vec![21,65,57]; let primary=&list[0]; list.push(98);
let mut list=vec![21,65,57]; let primary=list[0]; list.push(98);
Copy instead of reference.
Rust
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
foo = 63
foo=63
No spaces.
Shell
UPDATE products SET id='info' WHERE status=17
UPDATE products SET id='info' WHERE status=17;
Add semicolon.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
["test", 4]
["test", 4]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
const y = 41; y = 85;
let y = 41; y = 85;
Cannot reassign const.
JavaScript
if ($foo = 1)
if ($foo == 1)
Use ==.
Perl
if a = 18:
if a == 18:
Use == for comparison.
Python
yield foo
yield foo
Correct yield.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML