Java Script program to convert days into years, weeks and days

10. Write a Java Script program to convert days into years, weeks and days

java script programming

Write a Java Script program to convert days into years, weeks and days

We are required to write a JavaScript function that takes in a number (representing the number of days) and returns an object with three properties, namely −

And the properties should have proper values of these four properties that can be made from the number of days. We should not consider leap years here and consider all years to have 365 days.

Formula

				
					Number of years = (Number of days ) / 365
				
			

Code

				
					 <script>
        let d,y;
        d=parseInt(prompt("Enter d"))
        y=1/ 365

        alert(y)
    </script>
				
			

How do you convert days into years weeks and days?

				
					Number of years will be the quotient when number of days will be divided by 365 i.e days / 365 = years.
Number of weeks will be the result of (Number_of_days % 365) / 7.
Number of days will be the result of (Number_of_days % 365) % 7.
				
			
Spread the love