Glitched checking algorith for 8/9



So, my code worked perfectly, but i kept getting some error along the lines of "your code returns X instead of 'undefined'"
After rewriting my entire code to another one that works perfectly i rearranged some of the code and suddenly, with the exact same program returning the exact same code, the check mechanism gave in after like 5 tries.

Oops, try again. Your code returned 'paper wins!' instead of 'undefined' when the inputs are scissors and rock

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);

function compare(choice1,choice2) {
    if (choice1===choice2) {
        return ("The result is a tie!")   
    } else if (choice1==="rock") {
        if (choice2==="paper") {
            return("paper wins!")
        } else {
            return("rock wins!")
    } else if (choice1==="paper"){
        if(choice2==="rock") {
            return("paper wins!")
        } else {
            return("scissors win!")   
    } else if (choice1==="scissors") {
        if (choice2==="paper") {
            return("scissors win!")
        } else {
            return("paper wins!")   
    } // End of opening if and thus also last else if
} // End of function



HI it' s not a glitch just look well the instruction

Lastly, what if choice1 is "scissors"? Given choice1 is "scissors",

a. if choice2 === "rock", then "rock" wins.
b. if choice2 === "paper", then "scissors" wins. (this will be the else statement)


Weren't you supposed to print "rock wins!" and such instead of returning it?


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