Why can't I use return before the computerChoices?


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice < 0.34) {
    return computerChoice = "rock";
}
if (0.34 > computerChoice < 0.66) {
    return computerChoice = "paper";
}
else {
    return computerChoice = "scissors";
}


#2
  1. If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
  2. If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
  3. If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors".

Because as per these instructions, which need to be followed :wink:


#3

so when do you use return? I am confused


#4

function sum() {
  var add = 1 + 1;
  return add;
}

sum();

Take this example. Your function wants to display the sum of 1 + 1.
We'll calculate 1 + 1 and store it inside variable add.
Then we will return variable add to function sum()

In your exercise however, you need to store "rock", "paper", "scissors" in computerChoice.


#5

Thanks for clearing it up


#6

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