10-5 Logical Operators


#1

Hi there! What would be the best way to use the 'or' operators to create a random answer. I already have math.random running successfully, but I'm not sure exactly how to create another set of variables that will give the answer I'm looking for. I will paste my code below.
I'm looking for the first variable set in RUN

var math1 = Math.floor(Math.random()*2);

var user = prompt("You're walking down a road in Chernobyl, and you hear something. Do you INVESTIGATE, CONTINUE, or RUN?").toUpperCase();

switch(user){
case 'INVESTIGATE':
console.log("You find a mutant squirrel with 4 eyes, and five legs! You reach out to touch it.");
if( math1 >=0.5){
console.log("The mutant squirrel bites your hand, then runs away into the woods. You look at your hand, and see that it has ooze leaking, so you run off towards what look like buildings in the distance")
}else{
console.log("The mutant squirrel hisses at you, and runs away deep into the woods. Looking around, you spot some buildings in the distance, and make your way towards them.")
};
break;

case 'CONTINUE':
    console.log("You get the feeling that something is following you down the path...");

    if(){
     console.log("Curiosity stops you, and you look behind you. You don't know what you see, but it's huge, and terrifying! You run towards some buildings you see in the distance to hide.")    
    }else{
     console.log("Out of fear, you decide not to stick around and see what is following you, and run towards some buildings in the distance to hide.")
    };
    break;


case 'RUN':
    console.log("You run the opposite direction, over a river, and through the woods. When you stop, you're not a grandmother's house; you're lost!");
    if(){
        console.log("")
    }else{
        console.log("")
    };
    break;


default :
    console.log("*beep, beep, beep* Your radiation detector is going off, and when you turn to stop it, you wake up.");

};


#2

@microslayer67525,
Descibe in normal words
what you want to happen or do if the case is "RUN"


#3

I apologize. This is for the 'CONTINUE' option

I am trying to make it possible to randomly choose a number, and set fear and curiosity to different numbers, so it can randomly decide which answer to choose. This is for the 'OR' operator.


#4

@microslayer67525,

-1 using the random() Method for a Result of a zero or one

Math.random() return's a number Value in the range of 0 and 0.9999
If you multiple this returned number Value with 2
that would leave you a range
0...0.49 *2 ==> 0..0.99
0.50...0.999 *2 ==> 1....1,999

If you then do a Math.floor() that would lead to
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
0...0.49 *2 ==> 0..0.99 =>Math.floor() ==> 0
0.50...0.999 *2 ==> 1....1,999 => Math.floor() ==> 1

Thus the fear or curiosity variable has an associated _number Value of 0 OR 1
and you then use the Javascript truthy // falsy facility
https://developer.mozilla.org/en-US/docs/Glossary/Truthy

=========================================================

-2 using the random() Method for a Result in a scale of 1 to 10

Math.random() return's a number Value in the range of 0 and 0.9999
If you multiple this returned number Value with 10
that would leave you a range
Math.random()*10 ==> 0...0.999 * 10 ==> 0..9.99
(Math.random()*10) +1 ==> 1 .. 10.99
Math.floor( ( Math.random() * 10 ) + 1 ) ==> 1 .. 10