简体   繁体   English

我如何确定用户何时在 JavaScript 年满 18 岁?

[英]How do I determine when a user will turn 18 in JavaScript?

I am having trouble with task 9:我在执行任务 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

This should work:这应该工作:

const turn18 = new Date(db.getFullYear() + 18, db.getMonth(), db.getDate())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM