Why isn't my cont.style line working properly within each if condition?
I'm trying to update the height of my bars in the code where this function is called, but the main cont.style line under each if condition doesn't seem to be functioning correctly. Strangely, the one written under the else condition works perfectly fine.
I suspect there might be an issue with the if conditions or the parameters being passed to the update function. I even attempted passing array_size as a parameter, but the same error persists. The if condition is intended for mobile view, and within each nested if statement, the array size is adjusted to ensure that the bars are easily visible on mobile devices.
function update(cont, height, color) {
window.setTimeout(function() {
if (window.matchMedia("(max-width: 600px)").matches) {
if (array_size > 20 && array_size < 30) {
array_size = array_size % 10;
cont.style = " margin: " + margin_size + "%; width:" + (100 / array_size - (2 * margin_size)) + "%;
height: " + (height) + "% ;
background: " + color + ";
";
}
if (array_size > 30 && array_size < 40) {
array_size = array_size % 10 + 10;
cont.style = " margin: " + margin_size + "%; width:" + (100 / array_size - (2 * margin_size)) +
"%; height:" + (height) + "%; background:" + color + ";";
}
if (array_size > 40 && array_size < 50) {
array_size = array_size % 10 + 15;
cont.style = " margin: " + margin_size + "%; width:" + (100 / array_size - (2 * margin_size)) +
"%; height:" + (height) + "%; background:" + color + ";";
}
if (array_size == 30 || array_size == 40 || array_size == 50) {
array_size = array_size % 10 + 12;
cont.style = " margin: " + margin_size + "%; width:" + (100 / array_size - (2 * margin_size)) +
"%; height:" + (height) + "%; background:" + color + ";";
}
} else {
cont.style = " margin: " + margin_size + "%; width:" + (100 / array_size - (2 * margin_size)) +
"%; height:" + (height) + "%; background:" + color + ";";
}
}, delay += delay_time);
}