The result of my code

When I run my program, I get the expected output, but I also get an error:

"Your function does not return a value"

Here is my code:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} 
//console.log("Computer: " + computerChoice);

var compare = function(userChoice,computerChoice){
    if (userChoice === computerChoice) {
        return "The result is a tie";
        }
    else{
        return "False" ;
    }   
 };
var pp = compare(userChoice,computerChoice);
console.log(pp);

      

+3


source to share


1 answer


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice >= 0.34 && computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} 
//console.log("Computer: " + computerChoice);

var compare = function(userChoice,computerChoice){
    if (userChoice == computerChoice) {
        return "The result is a tie";
    }
    return "False" ;

 };
var pp = compare(userChoice,computerChoice);
console.log(pp);

      



+1


source







All Articles