Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading