Issue Description:
I have developed a code that retrieves words from a database and displays them in boxes on my webpage. Each box can hold up to three words, and the height of each box is determined by the height of the word inside it. This height information is stored in an array for later comparison. The objective is to ensure that every row of three boxes has uniform height with the tallest box setting the height for all three. However, I encountered a problem when processing the third row (Id[Ten] = 1) where the logic fails to properly set the heights resulting in overlapping text within the boxes.
var tempN = 0; //Temporary number holder
var temp = []; //Array to store box heights
for (var i = 0; i < Panels.length; i++) {
temp[i] = new Array();
if (document.getElementById('Column'+i+Id[Ten])!=null) {
document.getElementById('Column'+i+Id[Ten]).style.height = document.getElementById('Text'+i+Id[Ten]).clientHeight+"px";
temp[i].push(document.getElementById('Column'+i+Id[Ten]).clientHeight);
} else {
temp[i].push(0);
}
if (i%3 == 2) {
for (var x=2;x >= 0;x--) {
alert(temp[i-x]+" is greater than "+tempN);
if (tempN < temp[i-x]) {
tempN = temp[i-x];
alert(tempN+' '+temp[i-x]);
document.getElementById('Row'+BoxRow+Id[Ten]).style.height = tempN + "px";
}
}
tempN = 0;
}
}
temp = [];
Based on the current implementation, the array "temp" will contain the following values:
temp = [0,158,0,0,158,0,0,50,0] when Id[Ten] is 3
temp = [0,50,0,0,0,0,0,0,0] when Id[Ten] is 2
temp = [284,50,50,50,50,50] when Id[Ten] is 1
Error Identification:
The error manifests when processing the last scenario with Id[Ten] = 1. Even though the initial comparison correctly identifies the tallest box as 284, subsequent comparisons fail to recognize this and instead prioritize shorter heights like 50. This causes the final box height calculation to be incorrect leading to text overlap. It seems like the condition checks and comparisons are not working as expected causing inconsistency in the height calculations across the boxes. Any insights or suggestions on resolving this erratic behavior would be greatly appreciated.