Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
How do I determine when a user will turn 18 in JavaScript?

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This should work:

const turn18 = new Date(db.getFullYear() + 18, db.getMonth(), db.getDate())
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!