I am trying to write a basic progress bar with jQuery. I got al the parts that will display the progress in percentages, just need to debug my math.
So, if I start with 130 questions, every time the question is answered I need to recalculate and show the progress.
So here’s what I do
var questID // is current question ID, from 1 to 130
var startCount = 130;
var currentCount = startCount - questID;
var progress = Math.floor(currentCount / startCount * 100);
$("#progressBar").width(progress);
I think I get something backwards as when I test I get 99% after the first question… probably need more caffeine.
Your
currentCountlogic is wrong. If you have answered 1 question then:Then
129/130will give you the 99%. You just need1/130. Therefore you can usequestID: