Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Odin Project RPS

I'm working on TOP Rock, Paper, Scissors JS project and i cant figure out why the computerPlay comparison and play comparison is coming out invalid or undefined. I tried nested if else statements first, but they came out as invalid, then I added the extra =, still invalid. Now I tried switch statements and it's giving me undefined. If a second or third pair of eyes can look this over to see what's screwing me up, I'd appreciate it.

 

<DOCTYPE! html>
<html>
  <head>
    <title>Rock, Paper, Scissors</title>
  </head>
<body>
  <script>
  var player = 0
  var comp = 0

    function computerPlay(){
        let compPlay = ["Rock", "Paper", "Scissors"]
        compPlay = compPlay[Math.floor(Math.random()*compPlay.length)]
        return compPlay;
    }

    function round(playerSelection, computerSelection){
        playerSelection.toLowerCase()
        computerSelection.toLowerCase()

        switch(playerSelection){
            case 'paper':
            switch (computerSelection){
                case 'rock':
                    return "You win; paper beats rock";
                    break;
                case 'scissors':
                    return "You lose; scissors beat paper";
                    break;
                deafult:
                    return 'tie'
            }

            case 'rock':
            switch (computerSelection){
                case 'paper':
                    return 'You lose rock beats  paper';
                    break;
                case 'scissors':
                    return 'you win rock beats scissors';
                    break;
                deafult:
                    return 'tie'
            }

            case 'scissors':
            switch (computerSelection){
                case 'paper':
                    return 'you win scissors beats paper';
                    break;
                case 'rock':
                    return 'you lose rock beats scissors';
                    break;
                deafult:
                    return 'tie'
            }
        }

        /*if (playerSelection == computerSelection){
            return "Tie"
        }
        else if (playerSelection === 'paper' && computerSelection === 'rock'){
            return "You win; paper beats rock"
        }
        else if (playerSelection === 'paper' && computerSelection === 'scissors'){
            return "You lose; scissors beat paper"
        }
        else if (playerSelection === 'rock' && computerSelection === 'paper'){
            return 'You lose rock beats  paper'
        }
        else if (playerSelection === 'rock' && computerSelection === 'scissors'){
            return 'you win rock beats scissors'
        }
        else if (playerSelection === 'scissors' && computerSelection === 'paper'){
            return 'you win scissors beats paper'
        }
        else if (playerSelection === 'scissors' && computerSelection === 'rock'){
            return 'you lose rock beats scissors'
        }
        else{
            return "Invalid"
        }*/
    }
        
        
var play = prompt("WHat is your choice? ")
play.toLowerCase()
console.log(play)
const computer = computerPlay()
computer.toLowerCase()
console.log(computer)
console.log(round(play, computer))

 
   </script>
</body>
</html>
2 Replies
Copilot Lvl 3
Message 2 of 3

Re: Odin Project RPS

<DOCTYPE! html>
<html>
<head>
<title>Rock, Paper, Scissors</title>
</head>
<body>
&lt;script&gt;
var player = 0
var comp = 0

function computerPlay(){
let compPlay = ["Rock", "Paper", "Scissors"]
compPlay = compPlay[Math.floor(Math.random()*compPlay.length)]
return compPlay;
}

function round(playerSelection, computerSelection){
playerSelection.toLowerCase()
computerSelection.toLowerCase()

switch(playerSelection){
case 'paper':
switch (computerSelection){
case 'rock':
return "You win; paper beats rock";
break;
case 'scissors':
return "You lose; scissors beat paper";
break;
deafult:
return 'tie'
}

case 'rock':
switch (computerSelection){
case 'paper':
return 'You lose rock beats paper';
break;
case 'scissors':
return 'you win rock beats scissors';
break;
deafult:
return 'tie'
}

case 'scissors':
switch (computerSelection){
case 'paper':
return 'you win scissors beats paper';
break;
case 'rock':
return 'you lose rock beats scissors';
break;
deafult:
return 'tie'
}
}

/*if (playerSelection == computerSelection){
return "Tie"
}
else if (playerSelection === 'paper' && computerSelection === 'rock'){
return "You win; paper beats rock"
}
else if (playerSelection === 'paper' && computerSelection === 'scissors'){
return "You lose; scissors beat paper"
}
else if (playerSelection === 'rock' && computerSelection === 'paper'){
return 'You lose rock beats paper'
}
else if (playerSelection === 'rock' && computerSelection === 'scissors'){
return 'you win rock beats scissors'
}
else if (playerSelection === 'scissors' && computerSelection === 'paper'){
return 'you win scissors beats paper'
}
else if (playerSelection === 'scissors' && computerSelection === 'rock'){
return 'you lose rock beats scissors'
}
else{
return "Invalid"
}*/
}


var play = prompt("WHat is your choice? ")
play.toLowerCase()
console.log(play)
const computer = computerPlay()
computer.toLowerCase()
console.log(computer)
console.log(round(play, computer))


&lt;/script&gt;
</body>
</html>
Community Manager
Message 3 of 3

Re: Odin Project RPS

We are happy you are here! You are more likely to get a useful response if you are explicit about what your project entails, giving a few more details might help someone give you a nudge in the right directions.

Thanks for being here, sharing, and keeping our community awesome!
Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!