Tell us what’s happening:
Am I being daft?
The requirements are “given today’s date, and a birthday, give how many days until their next birthday”. So surely any of the results can only be a maximum of 366 days.
However Tests 6 & 7 are looking for days in excess of this…
What am I missing?
Also feel free to comment on my approach to solving this - dates in JavaScript throw me for a loop…
Your code so far
function daysUntilBirthday(today, birthday) {
const dateToday = Date.parse(today);
const monthBirthday = birthday.slice(0, birthday.indexOf("/"));
const dayBirthday = birthday.slice(birthday.indexOf("/") + 1);
const currentYear = today.slice(0, 4);
const currentYearBirthday = Date.parse(`${currentYear}-${monthBirthday}-${dayBirthday}`);
const nextYearBirthday = Date.parse(`${Number(currentYear) + 1}-${monthBirthday}-${dayBirthday}`);
return currentYearBirthday < dateToday ? ((nextYearBirthday - dateToday) / 86400000).toFixed(0) : ((currentYearBirthday - dateToday) / 86400000).toFixed(0)
}
console.log(daysUntilBirthday("2026-07-16", "9/7"));
console.log(daysUntilBirthday("2026-07-16", "7/16"))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Birthday Countdown
https://www.freecodecamp.org/learn/daily-coding-challenge/2026-07-17