Answered step by step
Verified Expert Solution
Question
1 Approved Answer
QUICK JAVASCRIPT QUESTION. Hello, I am making a program ins Java script that subtracts a date from the current date and outputs how many days
QUICK JAVASCRIPT QUESTION.
Hello, I am making a program ins Java script that subtracts a date from the current date and outputs how many days you have lived, but it is not printing out in my HTML page.
here is the code:
HTML CODE:
Todays Date and Time Is: | |
The Birthdate You Entered Is: | |
You Have Lived For: | |
var day1 = start(); | |
var day2 = middle(); | |
var days = 0 | |
days += (date1[0]-date2[0]) * 365 | |
days += (date1[1]-date2[1]) * 30 | |
days += (date1[2]-date2[2]) | |
document.getElementById("daysLived").innerHTML = days; | |
JAVASCRIPT CODE:
function start() { n = new Date(); y = n.getFullYear(); m = n.getMonth() + 1; d = n.getDate(); document.getElementById("currentDate").innerHTML = m + "/" + d + "/" + y; return[y, m, d] } function middle() { b = new Date(); mString = window.prompt("Enter Month You Were Born (1-12): "); dString = window.prompt("Enter Day You Were Born (1-31): "); yString = window.prompt("Enter The FULL Year You Were Born: "); m = parseInt(mString); d = parseInt(dString); y = parseInt(yString); document.getElementById("birthdate").innerHTML = m + "/" + d + "/" + y; return [y, m, d] } |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started