wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'title':56, 'value' 24}}
{{'title':56, 'value':24}}
Colon missing.
Python
String item = 'info';
String item = "info";
Double quotes.
Java
val count = 'info'
val count = "info"
Double quotes.
Kotlin
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
if ($foo = 92) {{}}
if ($foo -eq 92) {{}}
Use -eq.
PowerShell
'48' + 22
48 + 22
Avoid string coercion.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
let b = 'hello'
let b = "hello"
Double quotes.
Swift
$items[75]
if ($items.Count -gt 75) {{ $items[75] }}
Check bounds.
PowerShell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if z = 70 then print('test') end
if z == 70 then print('test') end
Use ==.
Lua
println('world')
println("world")
Double quotes.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print 'data'
print 'data';
Add semicolon.
Perl
bar = 95
bar=95
No spaces.
Shell
DELETE FROM items WHERE status=98
DELETE FROM items WHERE status=98;
Add semicolon.
SQL
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
[77, 98, 20
[77, 98, 20]
Close bracket.
Python
const index;
const index = 96;
Initialize const.
JavaScript
let z: Int = 'result'
let z: String = 'result'
Fix type.
Swift
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
73result = 10
result73 = 10
Variable cannot start with digit.
Python
id: world value: world,
id: world value: world
Remove comma.
YAML
if ($bar = 77)
if ($bar == 77)
Use ==.
Perl
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
let foo: i32 = "hello";
let foo: &str = "hello";
Type mismatch.
Rust
if (temp = 42)
if (temp == 42)
Use ==.
Scala
if count = 43
if count == 43
Use ==.
Go
if result > 86 puts 'data'
if result > 86 puts 'data' end
Add 'end'.
Ruby
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
else print('message')
else: print('message')
Colon after else.
Python
let y: number | null = null; y.toFixed(29);
let y: number | null = null; if(y!==null) y.toFixed(29);
Null check.
TypeScript
let b = 22; b += 1;
let mut b = 22; b += 1;
Need mut to modify.
Rust
let b = 99;
let b = 99;
Correct.
JavaScript
WHERE name = '1'
WHERE name = 1
Don't quote integer.
SQL
if [ $b = 15 ]; then
if [ "$b" = 15 ]; then
Quote variable.
Shell
$values[13] = 5;
if (isset($values[13])) $values[13] = 5;
Check existence.
PHP
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
result == '23'
result === 23
Use strict equality.
JavaScript
function handle(bar:string){{return bar;}} handle(60);
function handle(bar:string){{return bar;}} handle('hello');
Pass correct type.
TypeScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if (temp = 96) {{}}
if (temp === 96) {{}}
Use === for equality.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if data = 30:
if data == 30:
Use == for comparison.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
var val int = 'hello'
var val string = 'hello'
Type mismatch.
Go
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x int
var x int
Correct.
Go
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val num = 80; num = 14
var num = 80; num = 14
Use var for reassignment.
Scala
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
'hello' + 91
'hello' + 91.to_s
Convert int.
Ruby
switch(item){{ case 60: break; }}
switch(item){{ case 60: break; default: break; }}
Add default case.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
String name = 'value';
String name = 'value';
Correct.
Dart
jwt.sign({{id:82}}, 'token');
jwt.sign({{id:82}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{"value":"output" "status":21}}
{{"value":"output", "status":21}}
Add comma.
JSON
if (b = 20) {{}}
if (b == 20) {{}}
Use ==.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
items(15)
if length(items) >= 15, items(15), end
Check length.
MATLAB
<user><name>world</name><name>17</name></user
<user><name>world</name><name>17</name></user>
Add closing >.
XML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x = 26;
var x = 26;
Correct.
Dart
echo 'result'
echo 'result';
Add semicolon.
PHP
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
if (y = 80) {{}}
if (y == 80) {{}}
Use ==.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
int data[74]; data[74]=5;
int data[74]; if(74<74){{}} else data[74]=5;
Bounds check.
C++
x := 6
x := 6
Correct.
Go
{{'id':'value'}}
{{"id":"value"}}
Use double quotes.
JSON
assert count > 26
assert count > 26
Correct.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
result = world
result = 'world'
Quote strings.
Python
if x > 83 puts 'info'
if x > 83 puts 'info' end
Add 'end'.
Ruby
DELETE FROM products WHERE email=71
DELETE FROM products WHERE email=71;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if temp = 31
if temp == 31
Use ==.
Ruby
math.sqrt(65)
import math math.sqrt(65)
Import module first.
Python
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
UPDATE products SET email='info' WHERE email=63
UPDATE products SET email='info' WHERE email=63;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
name: result age: 65
name: result age: 65
Correct.
YAML