-6

I've been trying to make a few javascript based countdowns/timers to place around my web site... an example of this would be...

"I’m a 25-year-old part-time blogger & designer and full-time waitress & bartender!" where the "25" would increase every year to update the age.

another example would be...

"with my soon to be husband (COUNTDOWN TILL WEDDING HERE)" and change "soon to be husband" to "husband"

ive seen a few script round but not quite what i need..

I've been trying to use the Math.floor method which works for the amount of days but i need to figure out how to add years. is there a way to calculate years using math.floor?

sidenote * i am not very familiar with javascript or anything of the sort whatsoever

  • How did you try it and what was the problem? – juzraai Jul 24 '18 at 08:08
  • What technologies are you using? Is this a static HTML page, or are the pages generated dynamically? – Jamie Weston Jul 24 '18 at 08:08
  • 2
    [Here for the age](https://stackoverflow.com/questions/4060004/calculate-age-given-the-birth-date-in-the-format-yyyymmdd) and [here for countdown to a date](https://stackoverflow.com/questions/9335140/how-to-countdown-to-a-date) – Hearner Jul 24 '18 at 08:12

1 Answers1

0

You can use Javascript to do that:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome to My Page!</title>
</head>
<body>

<div id="about-me"></div>

</body>

<script>

function get_message() {
    var my_birthday = new Date("2/13/1996"); // update your birthday here
    var today = new Date();
    var time_diff = Math.abs(today.getTime() - my_birthday.getTime()); // get the difference in milliseconds between today's date and your birthday
    var my_age = Math.floor(time_diff / (1000 * 3600 * 24 * 365)); // get your age

    var s = document.getElementById('about-me');
    var message = "I’m a " + my_age.toString() + "-year-old part-time blogger & designer and full-time waitress & bartender!";
    s.innerHTML = message; // update your age
   }

window.onload = get_message; // load script only when page is loaded
</script>

</html>

Hope this helps!

user5305519
  • 3,008
  • 4
  • 26
  • 44