-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Consider how this could be refactored using fewer else if statements. Can some of them be nested?
rgero215_webFun_sept2017/WebFundamentals/Javascript/If You Dont Mind Can I Have The Time?/time.js
Lines 5 to 42 in 60270d6
| if (MINUTE < 30 && PERIOD == "PM" && HOUR > 6 && HOUR != 12) { | |
| console.log("It's just after", HOUR, "in the evening"); | |
| } else if (MINUTE < 30 && PERIOD == "PM" && HOUR < 6 && HOUR != 12) { | |
| console.log("It's just after", HOUR, "in the afternoon"); | |
| } else if (HOUR == 12 && MINUTE == 0 && PERIOD == "AM") { | |
| console.log("It's midnight"); | |
| } else if (HOUR == 12 && MINUTE == 0 && PERIOD == "PM") { | |
| console.log("It's noon"); | |
| }else if (MINUTE < 30 && PERIOD == "AM") { | |
| console.log("It's just after", HOUR, "in the morning"); | |
| } else if (MINUTE > 30 && PERIOD == "PM" && HOUR > 6) { | |
| HOUR +=1 | |
| console.log("It's almost", HOUR, "in the evening"); | |
| } else if (MINUTE > 30 && PERIOD == "PM" && HOUR < 6) { | |
| HOUR +=1 | |
| console.log("It's almost", HOUR, "in the afternoon"); | |
| } else if (MINUTE > 30 && PERIOD == "AM") { | |
| HOUR +=1 | |
| console.log("It's almost", HOUR, "in the morning"); | |
| } else if (MINUTE == 15 && PERIOD == "PM" && HOUR > 6) { | |
| console.log("It's quarter after", HOUR, "in the evening"); | |
| } else if (MINUTE == 15 && PERIOD == "PM" && HOUR < 6) { | |
| console.log("It's quarter after", HOUR, "in the afternoon"); | |
| } else if (MINUTE == 15 && PERIOD == "AM") { | |
| console.log("It's quarter after", HOUR, "in the morning"); | |
| } else if (MINUTE == 5 && PERIOD == "AM") { | |
| console.log("It's five after", HOUR, "in the morning"); | |
| } else if (MINUTE == 5 && PERIOD == "PM" && HOUR > 6) { | |
| console.log("It's five after", HOUR, "in the evening"); | |
| } else if (MINUTE == 5 && PERIOD == "PM" && HOUR < 6) { | |
| console.log("It's five after", HOUR, "in the afternoon"); | |
| } else if (MINUTE == 30 && PERIOD == "PM" && HOUR > 6) { | |
| console.log("It's half past", HOUR, "in the evening"); | |
| } else if (MINUTE == 30 && PERIOD == "PM" && HOUR < 6) { | |
| console.log("It's half past", HOUR, "in the evening"); | |
| } else if (MINUTE == 30 && PERIOD == "AM") { | |
| console.log("It's half past", HOUR, "in the morning"); | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels