<% for(var i = maximumGrade;i>=1;i--){ %> <% var width = 0; var maxWidth = 65; var avgGradeWidth = 0; if((i-1)< result.AvgGrade && i>result.AvgGrade) { avgGradeWidth=(result.AvgGrade - Math.floor(result.AvgGrade)) * 100 width= avgGradeWidth < maxWidth ? avgGradeWidth : maxWidth; } else if(i<= result.AvgGrade){ width=100; } %> <% } %>