# Thread: Need help in converting years to days,hours,minutes, and seconds.

1. ## Need help in converting years to days,hours,minutes, and seconds.

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!

2. Originally Posted by aaksu22
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.

Code javascript:
```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.

Code javascript:
```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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•