August 8th, 2024
What's missing in this code?
// Calculate age based on total number of days!
// Assume 1 month = 30 days
// console.log(explainAge(2349)); // 6 years, 5 months, 1 weeks, 2 days
// console.log(explainAge(6570)); // 18 years, 0 months, 0 weeks, 0 days
// console.log(explainAge(12234)); // 33 years, 6 months, 1 weeks, 2 days
function explainAge(totalDays)
const years = Math.
(totalDays / 365);
const remYears = totalDays % 365;
const months = Math.floor(remYears /
);
const remMonths = remYears % 30;
const weeks = Math.floor(remMonths / 7);
const
= remMonths
7;
const days = remWeeks;
return `${years} years, ${months} months, ${weeks} weeks, ${days} days`;
}
Type or select from these options