Reputation: 1
I am having trouble with task 9:
// Task #7) Prompt the user for their birthday and convert it to a Date object
// Remember - when prompting the user, it comes in as a string
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var birthDate = prompt("Enter your birthdate mm/dd/yyyy");
var bd = new Date(birthDate);
// Task #8) Display the date the user was born in a format that shows the day of the week, month, date, and year
document.write("You were born on " + days[bd.getDay()] + ", ");
document.write(months[bd.getMonth()] + " ");
document.write(bd.getDate() + ", " + bd.getFullYear() + "<br>");
// Task #9) Calculate when the user turned 18
// Task #10) Display the 18th birthday in a format
// that shows the day of the week, month, date, and year
Upvotes: 0
Views: 588
Reputation: 202
This should work:
const turn18 = new Date(db.getFullYear() + 18, db.getMonth(), db.getDate())
Upvotes: 1