Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

0

This should work:

const turn18 = new Date(db.getFullYear() + 18, db.getMonth(), db.getDate())
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda