Inconsistent result with Rock Paper Scissors Project

Hi All,

When i run the js code as in the link below the computerchoice value in the function getComputerChoice does not match the console.log(‘The computer threw:’ + computerChoice);

the outputs underlined in red should match everyone the code is run which isnt the case. Any reason why?

Screen Shot 2020-04-02 at 9.35.58 pm

Thanks
Jag

every time you call getComputerChoice(); function, a new random result is generated. Given you call this function twice, most of the times you will get different outputs.

agree but shouldn’t the value in the 2nd line and 4th line of the outout be the same on every run.

Basically the getComputerChoice function is passing the value to variable computerChoice

function playGame() {
const userChoice = getUserChoice(‘paper’);
const computerChoice = getComputerChoice();
console.log('You threw: ’ + userChoice);
console.log(‘The computer threw:’ + computerChoice);
console.log(determineWinner(userChoice, computerChoice));

Thanks
Jag

Yes and no. the 2nd line of your function doesn’t output anything to the console.

But given you store the result in a variable, the result will be consistent.

However, i think you overlooked line 24 of your program. You log a random computerChoice without doing anything with it. Doesn’t harm your program, but confuses you (and would confuse end users of your program as well)

seems like a console.log of the getcomputerChoice multiple times in the same run will generate a different result as shown below. Just wondering why its not the same ? :grinning:

Each time you call the function number is generated, resulting in different outputs (sometimes the same output)