Issue with Computer Choice


#1

I don't understand what I'm doing wrong:

var userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if(computerChoice === 0 - .33) {
    return "Condition A is true";
    console.log("Rock");
} else if(computerChoice === .34 - .66) {
    return "Condition A is false";
    return "Condition B is false";
    console.log("Paper");
} else {
    return "Condition A is false";
    return "Condition B is false";
    console.log("Scissors");
}

Halp pls!


#2

@gigasurfer32051

The Math.random() method will deliver a number with a value
in the range of 0_(included)_ upontill 0.9999_(1 excluded)_.

As you will have to divide the number range form 0_(inclusive)_ to 0,9999_(so 1 excluded)_
into 3 equal partitions
we have to use an if else-if else statement.
The if else-if else skeleton looks like:

    if (conditionA) {
               //conditionA is true
                //your code 
     } else if (conditionB) {
               //conditionA is false
               //conditionB is true
              //your code 
    } else {     // <=== !! Takes NO condition-statements !!
               //conditionA is false
               //conditionB is false
              //your code 
    }

following the Instructions the conditions would be:

  1. If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
    ( 0 <= computerChoice && computerChoice <= 0.33) which we capture at the IF using
    ( computerChoice <= 0.33)

  2. If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
    ( 0.33 < computerChoice && computerChoice < 0.67) which we capture at the ELSE IF as
    ( computerChoice < 0.67 )

  3. If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors".
    ( 0.67 <= computerChoice && computerChoice < 1) , you reached the ELSE level
    you can asume that computerChoice is greater equal to 0.67,
    the ELSE does NOT take a condition, just write your code.


#3

Aaaaaah! Now it's saying "illegal return statement"!


#4

@gigasurfer32051
You cannot use a return statement outside of a function definition....!!!

The other thing
if a return would be reached during a function execution
the return-Result is returned AND the the function will be exited....
a second return would never be reached.....

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return

PS.
In your IF ELSE-IF ELSE statement
you should re-assign the =computerChoice= variable with a string Value


#5

Oh, yeah! I'll have to backtrack to see how I did it, last time. I couldn't remember how I did it.


#6

I figured it out. Thank you!:slight_smile: