Skip to content

Commit 35906ee

Browse files
committed
make re-used code a function
1 parent e810473 commit 35906ee

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

modules/colors.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
if (opacity === 1) {
119119
cell.textContent = color;
120120
} else {
121-
cell.textContent = `${color}${hexOpacity(opacity)}`;
121+
cell.textContent = hexOpacity(color, opacity);
122122
}
123123
}
124124

@@ -187,19 +187,19 @@
187187
function setBackgroundColor(color, opacity) {
188188
const body = document.querySelector("div");
189189
if (opacity !== 1) {
190-
color = color + "" + hexOpacity(opacity);
190+
color = hexOpacity(color, opacity);
191191
}
192192
body.style.backgroundColor = color;
193193
opacityPicker.style.accentColor = color;
194194
colorPicker.style.accentColor = color;
195195
}
196196

197-
function hexOpacity(opacity) {
197+
function hexOpacity(color, opacity) {
198+
let char = "00"
198199
if (opacity > 0) {
199-
return Math.floor(opacity * 255).toString(16);
200-
} else {
201-
return "00";
200+
char = Math.floor(opacity * 255).toString(16);
202201
}
202+
return `${color}${char}`
203203
}
204204
</script>
205205
</body>

0 commit comments

Comments
 (0)