在条件中使用多个 else 块

using multiple else blocks in conditional

我不太清楚为什么我的代码不起作用。谁能帮忙? 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"; 
}

如果是else if ladder应该像下面这样

if (hours > 18) greeting = "Good Evening";
else if (hours > 12) greeting = "Good Afternoon";
else if (your condition missing here) greeting = "Good Morning";
else greeting = "Welcome Night Owl";

有关更多信息,请查看 this url

为了javascript你必须先学习基础编程,我建议你访问https://javascript.info 你应该试试这个希望它有意义

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);