Logical operators- need help


i can't edit my code according to instruction . Here is the instruction.

[Add some if/else statements to your cases that check to see whether one condition and another condition are true, as well as whether one condition or another condition are true. Use && and || at least one time each.]

var user = prompt("what do u want ? ").toUpperCase();

        console.log("red is a sweet color");
            console.log("its a bloody color");
            console.log("its a rest color");
            console.log("atleast u can take me");


You have three case blocks (which should not be indented, btw, only their content) with which to work. We are asked to check two conditions against each other so that would be the first step. Dream up two unique conditions.

You could have the user answer three questions:


Now there are three states. The color state will be the switch control, the other two will be used in the conditionals in each case.

There is another way we can write this so that it simulates user input for the latter two with random numbers.

var number = Math.floor(Math.random() * 100)
var age = Math.floor(Math.random() * 20 + 13)

Now the switch.

switch (color) {
case "red":
    if ( number < 50 && age < 16 ) {
        console.log("Lower half");
    } else {
        console.log("age or number are in upper half");
case "blue":
    if ( number > 50 || age > 16 ) {
        console.log("age or number are in upper half");
    } else {
        console.log("Lower half");
default: console.log("Color not found in list.");

Please use this as a model, not in your lesson. Thanks.


A post was split to a new topic: Need help wit else statement


sry , its difficult. May i get another explanation in different way ?


By this point in the course track you should have a handle on if..else if..else statements. If not, then may I recommend you back and review, or at least post some code of your own so we can discuss any errors or issues. As it is, I don't know where to start since I've as much as given you a complete solution to model from.

Do some more review and practice, and set this aside for a bit while you continue to learn the concepts. In time you should be able to return to this project and have a an easier time of it.


i understand if else statements , but why this code ? in maximum person use == or === , but '>' for what ?


To simiulate a user inputing a number less than 100 (including 0) and inputing an age less than 33 but greater than 12. It just gave us random values to use in the demo so we didn't have to input them.

We use simulation all the time when we play the computer. It is simulating a human player. LIkewise we can generate test responses when debugging our code so the inputs are bypassed.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.