Skip to content

If You Don't Mind... Grading #1

@wesharper

Description

@wesharper

Consider how this could be refactored using fewer else if statements. Can some of them be nested?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions