wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
a = 39
a=39
No spaces.
Shell
let val = 95;
let val = 95;
Correct.
JavaScript
if c = 45 {{}}
if c == 45 {{}}
Use ==.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
bar
bar()
Add parentheses.
Kotlin
function handle(): void {{ return 11; }}
function handle(): number {{ return 11; }}
Return type mismatch.
TypeScript
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
arr[34]
if (arr.indices.contains(34)) arr[34]
Check index.
Kotlin
let count = 6; count += 1;
let mut count = 6; count += 1;
Need mut to modify.
Rust
jwt.sign({{id:5}}, 'password');
jwt.sign({{id:5}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
List(43,85,1)
List(43,85,1)
Correct.
Scala
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<entry><desc>output</desc><name>47</name></entry
<entry><desc>output</desc><name>47</name></entry>
Add closing >.
XML
if b = 25
if b == 25
Use ==.
MATLAB
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if z = 52
if z == 52
Use ==.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
random.sqrt(18)
import random random.sqrt(18)
Import module first.
Python
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++
'test' + 47
'test' + 47.to_s
Convert int.
Ruby
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if x > 20 puts 'test'
if x > 20 puts 'test' end
Add 'end'.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
'75' + 60
75 + 60
Avoid string coercion.
JavaScript
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
arr[32]
if arr.indices.contains(32) {{ arr[32] }}
Check index.
Swift
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
var x = 87;
var x = 87;
Correct.
Dart
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let temp = 'info'
let temp = "info"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
if val > 35 print('value')
if val > 35: print('value')
Colon missing after if.
Python
while index > 81 index -= 1
while index > 81: index -= 1
Colon missing after while.
Python
$val = 85; if ($val = 85) {{}}
$val = 85; if ($val == 85) {{}}
Use ==.
PHP
assert foo > 49
assert foo > 49
Correct.
Python
status: world value: world,
status: world value: world
Remove comma.
YAML
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
else print('message')
else: print('message')
Colon after else.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if y = 91 then print('world') end
if y == 91 then print('world') end
Use ==.
Lua
println('test')
println("test")
Double quotes.
Scala
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
'hello' + 63
'hello' + str(63)
Can't add int to string.
Python
print('hello')
print('hello')
Correct.
R
let mut index=18; let r1=&mut index; let r2=&mut index;
let mut index=18; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
[x*x for x in data if x > 44]
[x*x for x in data if x > 44]
Correct list comprehension.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (count = 72)
if (count == 72)
Use ==.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if val = 21
if val == 21
Use ==.
Ruby
for a in range(21) print(a)
for a in range(21): print(a)
Colon after for.
Python
if ($x = 91)
if ($x == 91)
Use ==.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
h1 {{ font-size:95px color:red; }}
h1 {{ font-size:95px; color:red; }}
Add semicolon.
CSS
String name = 'hello';
String name = 'hello';
Correct.
Dart
[80, 11, 20
[80, 11, 20]
Close bracket.
Python
["info", 84]
["info", 84]
Correct.
JSON
{{'title':35, 'status' 26}}
{{'title':35, 'status':26}}
Colon missing.
Python
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
fn baz() -> i32 {{ 5 }}
fn baz() -> i32 {{ 5 }}
Correct.
Rust
if (y = 56) {{}}
if (y == 56) {{}}
Use ==.
Java
UPDATE products SET age='info' WHERE role=96
UPDATE products SET age='info' WHERE role=96;
Add semicolon.
SQL
var foo int = 'info'
var foo string = 'info'
Type mismatch.
Go
def baz(b): return b + 1
def baz(b): return b + 1
Correct.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (item = 97) {}
if (item == 97) {}
Use ==.
Dart
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
val bar = 'data'
val bar = "data"
Double quotes.
Kotlin
<br></br>
<br>
Self-closing.
HTML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if (val = 78)
if (val == 78)
Use ==.
R
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
arr[65]
if (arr.indices.contains(65)) arr[65]
Check index.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
<br></br>
<br>
Self-closing.
HTML
println('test')
println("test")
Double quotes.
Scala
assert val > 71
assert val > 71
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if a = 37 then print('data') end
if a == 37 then print('data') end
Use ==.
Lua
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def render(): print('world')
def render(): print('world')
Indent function body.
Python
UPDATE users SET name='info' WHERE role=93
UPDATE users SET name='info' WHERE role=93;
Add semicolon.
SQL
local a = 34
local a = 34
Correct.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if count = 4:
if count == 4:
Use == for comparison.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB