Why are the if and else statements not working?

Why are the if and else statements not working?

The if and else statements for choices ‘B’ and ‘C’ display nothing on the screen when they are typed in as user input. I’ve tried a few things but I cannot seem to figure it out.

What is the purpose of the else statement?

For one thing, unlike if and else if, an else statement is not used to do condition checking. The purpose of else is to execute alternative code in the situation where the if, and else if conditions return false. a < b returned false and a > b also returned false.

What to do if you get an if else error?

If you have a question that isn’t answered here, please use the green “Ask a question” button. Copy/paste all of your code in with your question, include the exercise number you are working on and the exact error message you are seeing. Typically the following error messages are caused by faulty if/else syntax

Why do I get an error when I put a semicolon after the else?

If you are getting an error about the else it is because you’ve told the interpreter that the ; was the end of your if statement so when it finds the else a few lines later it starts complaining. A few examples of where not to put a semicolon:

Why do I get an error about the else?

If you are getting an error about the else it is because you’ve told the interpreter that the ; was the end of your if statement so when it finds the else a few lines later it starts complaining. I think you can see what I’m getting at. Checked for all those and still haven’t found the bug yet?

Is there an indicator complaining about your else?

Okay, on to the next check. Is there an indicator complaining about your else? In JavaScript semicolons mark the end of statements. When you put a semicolon at the end of a condition, like this: if (choice1 === choice2); you are telling the interpreter to consider that as the end of your if statement.

Is there a way to take away the if and else statement?

Take away the else if and else, and we are left with clean, readable code. Notice that I’ve also changed the style to be fast return opposed to single return statement — it simply doesn’t make sense to continue testing a value if the correct one has already been found.

When to replace if statement with something else?

Know when to even eliminate Ifs entirely, by replacing them with objects. Often, you’ll find yourself having to extend some part of an application. As a junior developer, you may be inclined to do so by just adding an extra If-Else (i.e. else-if) statement.