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

199
Vistas
How do you find the difference in dates between a date selector and todays date with an error message if date is less than a certain amount of days

I am a very new learner and have been trying to learn as I go and I am completely stumped. I need to do the following and I cannot figure it out.

  1. You have to write a function called “dateDiff” that accepts one date parameter and returns the number of days between the birthday provided and the current date.

  2. Print “fname lname you have been breathing for ### days!” where ### is the number returned by your dateDiff() function. Remember to convert milliseconds to days and only return the integer(whole) number of days.

If the number of days is less than (365*18) then print “You are probably not old enough to take this class!”

Now, I have already created the following: (User id, Fname, Lname, Birthday,) as part of a login screen. Below is the code that I have written so far. Please be kind. This is my first crack at javascript.

Thank you!

HTML

<label for="birthday">Birthday:</label><br><br>
    <input class="form-control" type="date" name="datestart" value="" class="datepicker" required="" 
        placeholder="birthday" oninvalid="this.setCustomValidity('Invalid Birthday')">

JS

var d1 = new Date();
    var d2 = new Date() 

    var diff = d2.getTime() - d1.getTime();   
    var daydiff = diff / (1000 * 60 * 60 * 24);  
    document.write(" Total number of days between <b> " + d1 + " </b> and <b> " + d2 + " </b> is: <b> " + daydiff + " days </b>" ); 
about 4 years ago · Juan Pablo Isaza
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