Need your feedback to see my mistakes in Rock Paper Scissors!


#1

Hello!
I have made my first try to make the Rock Paper Scissor game, and so far I have tried to create the first two functions computerPlay and playRound. Would anyone like to help give me some feedback on what I have done wrong in this? I am sure there are many mistakes but I do not know how to continue :smile:
Thank you for reading and appreciate all feedback!

function computerPlay() {
let randomInt = Math.floor(Math.random() * 100);
if (randomInt <= 33) {
computerPlay = ‘Rock’;
} else if (randomInt <= 66) {
computerPlay = ‘Paper’;
} else {
computerPlay = ‘Scissors’;
}
}

function playRound(playerSelection, computerSelection) {

if (playerSelection.toLowerCase() == computerSelection.toLowerCase()) {
    return "It's a tie, nobody wins this round!";
} else if (playerSelection.toLowerCase() == 'rock' && computerSelection == 'Paper') {
    return 'You loose, Paper beats Rock!';
} else if (playerSelection.toLowerCase() == 'rock' && computerSelection == 'Scissors') {
    return 'You win, Rock beats Scissors!';
} else if (playerSelection.toLowerCase() == 'paper' && computerSelection == 'Rock') {
    return 'You win, Paper beats Rock!';
} else if (playerSelection.toLowerCase() == 'paper' && computerSelection == 'Scissors') {
    return 'You loose, Scissors beat Paper!';
} else if (playerSelection.toLowerCase() == 'scissors' && computerSelection == 'Paper') {
    return 'You win, Scissors beat Paper!';
} else {
    return 'You loose, Rock beats Scissors!';
}

}​


#2

I just took a quick look at the computerPlay function. You dont want to declare variables for computerPlay. Instead, you simply return the value, like so:

function computerPlay() {
let randomInt = Math.floor(Math.random() * 100);
  if (randomInt <= 33) {
     return "Rock";
  } else if (randomInt <= 66) {
     return "Paper";
  } else {
     return "Scissors";
  }   
}

#3

Thank you so much, that is very helpful! Still trying to figure all of this out, and just these little tips to poke you to the right direction are so nice when you feel lost :slight_smile: