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.
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.
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>" );