I just dont get what to do, I have thought of the process of putting the formulas together. I had thought of creating variables for each unit. But, one question dawns to me is that I dont know what to put as the variable for days if the variable of years would be 365, hours 24, seconds 60. Im at a loss, I am still new to JavaScript and have been searching for 3 hours. I dont know how to put the pieces together in putting it into an equation to post on an HTML. PLEASE HELP! (:
Let’s start with an assumption, that you are just converting years in to some other unit.
function convertYears(years, unit) {
}
We can make sure that years is a numeric value, and that unit is one of months, days, hours, minutes, or seconds.
function convertYears(years, unit) {
years = Number(years) || 0;
var time;
switch (unit) {
case 'months':
// time = ...
break;
case 'days':
// time = ...
break;
case 'hours':
// time = ...
break;
case 'minutes':
// time = ...
break;
case 'seconds':
// time = ...
break;
default:
return;
}
return time;
}
Now you just need to fill in those commented areas to complete the task.