[JavaScript] I am trying to call one function to another function which calls an array.
I want to call 2nd Example to 1st Example, or to convert the colours of 2nd Example to 1st Example. But nothing works. See the 3rd silly and stupid example:
1) Example:
document.querySelector('input[type=color]').onchange = e => {
const hexColor = e.srcElement.value
document.body.style.background = telinkrinizeColor(hexColor)
}
function telinkrinizeColor (hexColor) {
const [minLight, maxLight] = [32, 77]
let [, red, green, blue] = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexColor)
.map(hex => parseInt(hex, 16) * 100 / 255)
let maxColor = Math.max(red, green, blue)
let minColor = Math.min(red, green, blue)
let light = (minColor + maxColor) / 2
light = Math.max(Math.min(light, maxLight), minLight)
return `hsl(195, 34%, ${light}%)`
}
2) Example:
let titlenames = ["original", "telinkrin"];
let colours = ["#000", "#000009", "#0064A2", "#006575", "#ff99cc", "#DE6161", "#F0CA2A", "#FE4401", "#DFDFDF", "#00FF00"];
function attachNewNode(target, colours, titlenames)
{
let length = colours.length;
for (let i = 0; i < length; i++)
{
let node = document.createElement('div');
node.className = 'palette';
node.title = parseInt(i+1) + " – " + titlenames;
node.style = `background-color: ${colours[i]}`;
node.textContent = parseInt(i+1);
target.appendChild(node);
}
}
attachNewNode(document.getElementById("demo1"), colours, titlenames[0]);
attachNewNode(document.getElementById("demo2"), colours, titlenames[1]);
3) Example:
function getColours()
{
for (let i = 0; i < length; i++)
{
const hexColor = colours[i];
colours = telinkrinizeColor(hexColor);
}
return getColours();
}
attachNewNode(document.getElementById("demo1"), colours, titlenames[0]);
attachNewNode(document.getElementById("demo2"), getColours[colours], titlenames[1]);