Question: how to calculate percentage of a number in javascript?
Answer: You divide the number you you want to get the percentage for by the number you're getting the percentage of, then multiply it by 100 and do a Math. ... 
var wholePercent = Math.floor(3/9*100);
To turn it into a function:
function getWholePercent(percentFor,percentOf) ... 
call it like this:
var wholePercent=getWholePercent(3,9);