How can I create month and day as constant in JavaScript?
How can I create a breath day (month and day) as constant in JavaScript? I want to create a "Happy Breath" greeting on the site (html5) for every breath day if the else function. On the day of the breath day, it will show the greeting text. Like this
name breath day (month day) Today if today is name (month-day) text greeting document write text.
Thank.
<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>
+3
source to share
2 answers
Perhaps this is exactly 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>
+2
source to share