Skip to content

Commit de47172

Browse files
committed
write JS a different way
1 parent ca1a786 commit de47172

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

modules/colors.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,40 @@
7373
createColor();
7474
});
7575

76-
const createColor = function() {
76+
function createColor() {
7777
const currentColor = colorPicker.value;
7878
const currentOpacity = opacityPicker.value;
7979
setBackgroundColor( currentColor, currentOpacity );
8080
createHEX( currentColor, currentOpacity );
8181
createRGB( currentColor, currentOpacity );
8282
}
8383

84-
const createHEX = function ( color, opacity ) {
84+
function createHEX ( color, opacity ) {
8585
const cell = document.querySelector( "#HEX td" );
8686
if ( opacity == 1 ) {
87-
cell.innerHTML = color;
87+
cell.textContent = color;
8888
} else {
89-
cell.innerHTML = color + hexOpacity( opacity );
89+
cell.textContent = color + hexOpacity( opacity );
9090
}
9191
}
9292

93-
const createRGB = function ( color, opacity ) {
93+
function createRGB ( color, opacity ) {
9494
const cell = document.querySelector( "#RGB td" );
9595
color = color.substring( 1, 6 );
96-
let hexArray = color.match( /.{1,2}/g );
97-
let R = parseInt( hexArray[0], 16 ),
98-
G = parseInt( hexArray[1], 16 ),
99-
B = parseInt( hexArray[2], 16 );
96+
const hexArray = color.match( /.{1,2}/g );
97+
const R = parseInt( hexArray[0], 16 );
98+
const G = parseInt( hexArray[1], 16 );
99+
const B = parseInt( hexArray[2], 16 );
100100

101101
if( opacity == 1 ) {
102-
cell.innerHTML = `rgb(${R} ${G} ${B})`;
102+
cell.textContent = `rgb(${R} ${G} ${B})`;
103103
} else {
104-
cell.innerHTML = `rgb(${R} ${G} ${B} / ${opacity})`;
104+
cell.textContent = `rgb(${R} ${G} ${B} / ${opacity})`;
105105
}
106106
createHSL( R, G, B, opacity );
107107
}
108108

109-
const createHSL = function ( r, g, b, opacity ) {
109+
function createHSL ( r, g, b, opacity ) {
110110
const cell = document.querySelector( "#HSL td" );
111111
r = r / 255,
112112
g = g / 255,
@@ -138,27 +138,27 @@
138138
l = +( l * 100 ).toFixed( 1 );
139139

140140
if( opacity == 1 ) {
141-
cell.innerHTML = `hsl(${h} ${s}% ${l}%)`;
141+
cell.textContent = `hsl(${h} ${s}% ${l}%)`;
142142
} else {
143-
cell.innerHTML = `hsl(${h} ${s}% ${l}% / ${opacity})`
143+
cell.textContent = `hsl(${h} ${s}% ${l}% / ${opacity})`
144144
}
145145
createHWB( h, s, l, opacity );
146146
}
147147

148-
const createHWB = function ( h, s, l, opacity ) {
148+
function createHWB ( h, s, l, opacity ) {
149149
const cell = document.querySelector( "#HWB td" );
150150
const hsv = s * ( l < 50 ? l : 100 - l ) / 100;
151151
const W = hsv === 0 ? 0 : 2 * hsv / ( l + hsv ) * 100;
152152
const B = l + hsv;
153153
if( opacity == 1 ) {
154-
cell.innerHTML = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}%)`;
154+
cell.textContent = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}%)`;
155155
}
156156
else {
157-
cell.innerHTML = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}% / ${opacity})`;
157+
cell.textContent = `hwb(${h} ${W.toFixed( 1 )}% ${B.toFixed( 1 )}% / ${opacity})`;
158158
}
159159
}
160160

161-
const setBackgroundColor = function ( color, opacity ) {
161+
function setBackgroundColor ( color, opacity ) {
162162
const body = document.querySelector( "div" );
163163
if( opacity != 1 ) {
164164
color = color + "" + hexOpacity( opacity );
@@ -168,14 +168,14 @@
168168
colorPicker.style.accentColor = color;
169169
}
170170

171-
const hexOpacity = function( opacity ) {
172-
if( opacity > 0 ) {
171+
function hexOpacity( opacity ) {
172+
if( opacity > 0 ){
173173
return Math.floor( opacity * 255 ).toString( 16 );
174174
}
175175
else {
176176
return "00";
177177
}
178-
}
178+
}
179179
</script>
180180
</body>
181181
</html>

0 commit comments

Comments
 (0)