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

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>
1 Reply
Copilot Lvl 2
Message 2 of 2

Re: Odin Project RPS

GitHub, Inc.
c/o Incorporating Services, Ltd.
7801 Folsom Boulevard
Suite 202
Sacramento, CA 95826