I have a calculation function and part of this shows the number of days it will take to achieve a goal.
Rather than just show the number of days I want to calculate this into days & months or days, months and years depending on the number. I have an if statement for the splitting but can't seem to work out the maths to go from for example 132 days to x days x months... Any suggestions?
// GOAL
var timeToGoal = Math.round(goal / costPerDay);
// if more than a year
if ( timeToGoal >= 365 ) {
alert('days + months + years');
// if more than a month but less than a year
} else if ( timeToGoal >= 30 && timeToGoal <=365 ) {
alert('Days + months');
} else {
alert('days');
$('#savings-goal span').text(timeToGoal+' days');
}