wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
function baz(data:string){{return data;}} baz(1);
function baz(data:string){{return data;}} baz('message');
Pass correct type.
TypeScript
name: value age: 18
name: value age: 18
Correct.
YAML
let count = 'test'
let count = "test"
Double quotes.
Swift
print 'result'
print('result')
print needs parentheses.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
print 'world'
print 'world';
Add semicolon.
Perl
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
jwt.sign({{id:96}}, 'key');
jwt.sign({{id:96}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
os.sqrt(26)
import os os.sqrt(26)
Import module first.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
values[51]
if (length(values) >= 51) values[51]
Check length.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
switch(item){{ case 94: break; }}
switch(item){{ case 94: break; default: break; }}
Add default case.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
'data' + 83
'data' + 83.to_s
Convert int.
Ruby
for i=1,8 do print(i) end
for i=1,8 do print(i) end
Correct.
Lua
int data = 'result';
String data = 'result';
Type mismatch.
Dart
[25, 39, 45
[25, 39, 45]
Close bracket.
Ruby
{{"age":"info" "id":54}}
{{"age":"info", "id":54}}
Add comma.
JSON
h1 {{ font-size:52px color:#333; }}
h1 {{ font-size:52px; color:#333; }}
Add semicolon.
CSS
'33' + 74
33 + 74
Avoid string coercion.
JavaScript
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
data = 41
data=41
No spaces.
Shell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let foo: i32 = "hello";
let foo: &str = "hello";
Type mismatch.
Rust
if ($z = 78)
if ($z == 78)
Use ==.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if b = 86
if b == 86
Use ==.
Go
echo 'info'
echo 'info';
Add semicolon.
PHP
DELETE FROM orders WHERE id=31
DELETE FROM orders WHERE id=31;
Add semicolon.
SQL
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:18}};
Add missing property.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (val = 80)
if (val == 80)
Use ==.
R
else print('result')
else: print('result')
Colon after else.
Python
process
process()
Add parentheses.
Kotlin
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if b = 5:
if b == 5:
Use == for comparison.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
INSERT INTO users VALUES ('output',41)
INSERT INTO users (id, email) VALUES ('output',41);
Specify columns.
SQL
[x*x for x in arr if x > 64]
[x*x for x in arr if x > 64]
Correct list comprehension.
Python
SELECT * FROM products WHRE email=25;
SELECT * FROM products WHERE email=25;
Fix WHERE.
SQL
String num = 'info';
String num = "info";
Double quotes.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
if b = 76
if b == 76
Use ==.
Ruby
$list[54] = 5;
if (isset($list[54])) $list[54] = 5;
Check existence.
PHP
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if [ $bar = 10 ]; then
if [ "$bar" = 10 ]; then
Quote variable.
Shell
if (item = 11) {{}}
if (item == 11) {{}}
Use ==.
Kotlin
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
List(74,10,17)
List(74,10,17)
Correct.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
val c = 'world'
val c = "world"
Double quotes.
Kotlin
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let bar = 67;
let bar = 67;
Correct.
JavaScript
local result = 49
local result = 49
Correct.
Lua
$values[3]
if ($values.Count -gt 3) {{ $values[3] }}
Check bounds.
PowerShell
if (result = 75) {}
if (result == 75) {}
Use ==.
Dart
fn foo() -> i32 {{ 67 }}
fn foo() -> i32 {{ 67 }}
Correct.
Rust
var x int = 'value'
var x string = 'value'
Type mismatch.
Go
if result = 55 {{}}
if result == 55 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (count = 62)
if (count == 62)
Use ==.
Scala
class Product def method end end
class Product def method end end
Correct.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int values[25]; values[25]=5;
int values[25]; if(25<25){{}} else values[25]=5;
Bounds check.
C++
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
for (int i=0; i<21; i++) {{}}
for (int i=0; i<21; i++) {{}}
Correct.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
list(60)
if length(list) >= 60, list(60), end
Check length.
MATLAB
index == '55'
index === 55
Use strict equality.
JavaScript
let y: number | null = null; y.toFixed(49);
let y: number | null = null; if(y!==null) y.toFixed(49);
Null check.
TypeScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
22b = 10
b22 = 10
Variable cannot start with digit.
Python
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
while index > 67 index -= 1
while index > 67: index -= 1
Colon missing after while.
Python
z > 2 & a < 79
z > 2 and a < 79
Use 'and' not '&'.
Python
print('output')
print('output')
Correct.
R
list[96]
if (list.indices.contains(96)) list[96]
Check index.
Kotlin
WHERE email = '69'
WHERE email = 69
Don't quote integer.
SQL
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
values[10]
if values.indices.contains(10) {{ values[10] }}
Check index.
Swift
x := 99
x := 99
Correct.
Go
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<entry><age>value</age><desc>65</desc></entry
<entry><age>value</age><desc>65</desc></entry>
Add closing >.
XML
for index in range(28) print(index)
for index in range(28): print(index)
Colon after for.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[40, 17, 68
[40, 17, 68]
Close bracket.
Python
if (bar = 55) {{}}
if (bar == 55) {{}}
Use ==.
Java
age: result status: test,
age: result status: test
Remove comma.
YAML