Function Problem


#1

Good night everyone. I'm a begginer, as u guys will see. can somebody help me?

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4

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?");
console.log(userChoice)
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  if (userChoice === "rock"){
    if (computerChoice ==="scissors"){
        return "rock wins";
        }
        else {
        return "paper wins";
        }}
        else if (userChoice==="paper"){
            if(computerChoice==="rock"){
                return " paper wins"}
                else{
                    return"scissors wins"}
        }
        else{
            if(computerChoice === "paper"){
                return "scissors wins"}
                else{
                    return "paper wins."}
        }}
        
 compare()

#2

compare(userChoice,computerChoice);

The SCT is not expecting the final else if block to exist yet. The function should return undefined. Comment out or remove that segment of code, and add it back in the next lesson.


#3

thank u. But there's still a problem. I'm sorry to bother again.In the next step, however is my choice among rock, paper or scissor the result is always a tie. the compare function it's not working. but thank u so far for ur help.
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/5


#4

Are you getting any error messages, or just not seeing any output?

console.log(compare( ..., ... ));

to see the output.


#5

i'm not seeing any error message but i'm seeing the output.
the output is always" the result is a tie" though.
Like that:
User:rock
Computer: scissors
"The result is a tie!"


#6

else if (userChoice = "scissors") {
    if ( ... ) {

#7

A post was split to a new topic: call your compare function with userChoice and computerChoice as the arguments