I'm a little new to Javascript. I'm doing on a project for work and I'm having some trouble getting a method to return a percentage.
function campaignProgress(goal, current){
this.goal = goal;
this.current = current;
this.percent = Math.floor(current / goal * 100);
this.getGoal = function(){
return goal;
}
this.getCurrent = function(){
return current;
}
this.getPercent = function(){
return percent;
}
}
var totalProgress = new campaignProgress(1.70, 1.064);
When I call it in the html file I reference the .js file in my header and in the body I use;
<script type="text/javascript">
document.write(totalProgress.getGoal());
document.write(totalProgress.getPercent());
</script>
The getGoal() method works fine but getPercent() returns nothing. I can reference the percent variable itself like this;
totalProgress.percent
and it'll print fine. Any advice on why this is not working would be appreciated, thanks.