I am working on a function that'd greet its users with a time-aware greeting (Good Morning, Afternoon, Evening, Night). Here's the script that I've made
import moment from "moment";
function generateGreetings(){
if (moment().isBetween(3, 12, 'HH')){
return "Good Morning";
} else if (moment().isBetween(12, 15, 'HH')){
return "Good Afternoon";
} else if (moment().isBetween(15, 20, 'HH')){
return "Good Evening";
} else if (moment().isBetween(20, 3, 'HH')){
return "Good Night";
} else {
return "Hello"
}
}
$("greet")
.css({
display: "block",
fontSize: "4vw",
textAlign: "center",
})
.text(generateGreetings() +", name")
But it simply wont work and just returns "Hello". I've also tried using
var currentTime = moment();
var currentHour = currentTime.hour();
and use currentHour
to replace moment()
inside the function but when I do so the site just dissapears.
Hoping anyone here has any insight on what I should do to fix this issue.