using multiple else blocks in conditional

I’m not quite sure why my code is not working. Can anyone help?
javascript

/*if statements below*/

if (hours > 18) {
greeting = "Good Evening"
}

else if(hours > 12) {
greeting = "Good Afternoon";
}

else {
greeting = "Good Morning";

} 
else  {
greeting = "Welcome Night Owl"; 
}

>Solution :

You must learn about basic programming first for javascript, I will suggest you visit https://javascript.info
You should try this hope it makes sense

const hours = 12;

if (hours <= 18 && hours > 12) {
greeting = "Good Evening"
}

else if(hours == 12) {
greeting = "Good Afternoon"
}

else if(hours >= 4 && hours < 12){
greeting = "Good Morning"

} 
else{
greeting = "Welcome Night Owl"
}
console.log(greeting);

Leave a Reply