Why is this an error! PLEASE HELP!


#1


I don't understand why I can´t get the userChoice at the end! please anyone help!


var validateInput = function() { 
    var userChoice = prompt("Do you choose rock, paper or scissors?");
     if (userChoice === "rock" || userChoice === "paper" || userChoice === "scissors"){
    return(userChoice);
    } 
    else {
     validateInput();
    }
    
};

validateInput();

var cat = function (dog){
    return(dog);
};

cat(userChoice);


#3

i would place the function call after the function:

var validateInput = function() { 
    var userChoice = prompt("Do you choose rock, paper or scissors?");
     if (userChoice === "rock" || userChoice === "paper" || userChoice === "scissors"){
    console.log(userChoice);
    } 
    else {
     validateInput();
    }
    
};
 // function call here

then store the result of the function call in userChoice, and then make sure your function returns userChoice instead of logging it to the console.

If you need more help, post an updated version of your code


#4

Ok I just did it, know I want to call another function but it does not work :frowning:

var validateInput = function() {
var userChoice = prompt("Do you choose rock, paper or scissors?");
if (userChoice === "rock" || userChoice === "paper" || userChoice === "scissors"){
return(userChoice);
}
else {
validateInput();
}

};

validateInput();

var cat = function (dog){
return(dog);
};

cat(userChoice);


#5

var validateInput = function() {
var userChoice = prompt("Do you choose rock, paper or scissors?");
if (userChoice === "rock" || userChoice === "paper" || userChoice === "scissors"){
return(userChoice);
}
else {
validateInput();
}

};

validateInput();

var cat = function (dog){
return(dog);
};

cat(userChoice);


#6

why this:

var cat = function (dog){
return(dog);
};

?

you should store the result of the function call in a variable:

variable = validateInput();

and you might need to return the function call in else, so that a return keyword is always reached


#7

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