简体   繁体   中英

How to create month and day as constant in JavaScript?

How to create the breath day (month and day) as constant in JavaScript? I wont to create a "Happy breath day" greeting on website (html5) for each breath day with if else function. On the breath day date it will show some text for greeting. Like this

name breath day(month day) today if today name (month day) text greeting document write text.

Thanks.

<div id="happy">
  <script>
    function myFuntion {
      var today = new Date();
      var name = name.setDate(setMonth(23, 4);
        var text;
        if (today == name) {
          text = "Happy Breath Day";
        } else {
          text = " ";
        }
      }
      document.write("<div>" + text + "<\/div>");

  </script>
</div>

Possibly this is what you are trying to do?

 var today = new Date(); var breathDay = new Date(1972, 4, 23); var text; if (today.getMonth() === breathDay.getMonth() && today.getDate() === breathDay.getDate()) { text = 'Happy Breath Day!'; } else { text = 'Not today.'; } document.getElementById('happy').textContent = text; 
 <div id="happy"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM