Rock, paper, scissors project - function not running


#1

Hi all,

Having a problem with my code. In my console, I can only get the message “who knows who won - I didn’t write the code yet” to come up. The playerSelection which is always rock, and the computerSelection which changes based on the function computerPlay always show up as they are console.logged out

Any ideas?

Rock, Paper, Scissors

const items = ['rock', 'paper', 'scissors'];
    function computerPlay() {
        return items[Math.floor(Math.random()*items.length)];
    }
    const computerSelection = computerPlay().toLowerCase;  
    const playerSelection = 'rock';

    console.log(computerPlay(items));
    console.log(playerSelection);
    
    function playRound(playerSelection, computerSelection) {
        if(playerSelection === 'rock' && computerSelection === 'paper') {
            return "You lose! Paper beats rock!";
        } else {
            return "who knows who won - I didn't write the code yet";
        }
    }
    console.log(playRound());

    </script>
    
</body>

#2

Hello,

There are a few things that need to be changed.

On the following line:
const computerSelection = computerPlay().toLowerCase;
This needs to be changed to:
const computerSelection = computerPlay().toLowerCase();

The parentheses are needed since toLowerCase is a function.

On the following line:
console.log(computerPlay(items));
This needs to be changed to:
console.log(computerSelection);

The variable computerSelection is randomly choosing from rock, paper, or scissors. However, if you console log computerPlay(), you are randomly choosing from rock, paper, scissors again. So these two lines will not give the same value. For example, computerSelection will get rock, but console.log(computerPlay()) will get ‘paper’

On the following line:
console.log(playRound());
you need to put in the variables playerSelection and computerSelection so it looks like this:
console.log(playRound(playerSelection, computerSelection));

What is happening is that null values are being passed in, so you will always get ‘who knows who won’.

Hopefully that helps.