Https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors

happy new year all. The link i posted as in the title leads to codecademy paper, scissors, rock project. In the determine winner function(no. 7) i used my own code as against the one provided by the project. it looks good but it wouldnt run. I need help proofing it. see code below:

const determineWinner=function(userChoice, computerChoice){
  if(userChoice === computerChoice){return 'The game is a tie'}
  else if(userChoice === 'paper' && computerChoice === 'rock'){return 'You won'}
  else if(userChoice === 'paper' && computerChoice === 'scissors'){return 'computer won'}
  else if(userChoice === 'rock' && computerChoice === 'paper'){return 'computer won'}
  else if(userChoice === 'rock' && computerChoice === 'scissors'){return 'You won'}
  else if(userChoice === 'scissors' && computerChoice === 'rock'){return 'computer won'}
  else if(userChoice === 'scissors' && computerChoice === 'paper'){return 'You won'} else{return 'error'}               };
1 Like

did you call the function? Functions only execute when called, looking at the code, you only defined the function

1 Like

‎Yes I did call the function. I only copied out the if/else statement. I hoped to ascertain‎ if the code I used is acceptable for the project.

1 Like

Why didn’t you just copy paste your full code? Makes it a lot easier to help you

the url in the title is also really difficult to select, so i post it again:

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors

and not running is very vague. I pasted your determine winner function in the solution, and apart from bomb everything seems to go quite okay. Please better describe the issue and ensure we can replicate it.

1 Like

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors…the link.

the code below:

const getUserChoice=function(userInput){
  userInput = userInput.toLowerCase();
 if(userInput==='rock' || userInput===  'paper' || userInput==='scissors'){return userInput}else{console.log('error')}};

const getComputerChoice=function(){let randomNumber=Math.floor(Math.random()*3);
switch(randomNumber){
  case 0:
    return 'rock';
    break;
  case 1:
    return 'paper';
    break;
  case 2: 
    return 'scissors';
    break;
  default:
    return 'error';
    break;} };

const determineWinner=function(userChoice, computerChoice){if(userChoice === computerChoice){return 'The game is a tie'}
else  if(userChoice === 'paper' && computerChoice === 'rock'){return 'You won'}else if(userChoice === 'paper' && computerChoice === 'scissors'){return 'computer won'}else if(userChoice === 'rock' && computerChoice === 'paper'){return 'computer won'}else if(userChoice === 'rock' && computerChoice === 'scissors'){return 'You won'} else if(userChoice === 'scissors' && computerChoice === 'rock'){return 'computer won'}else if(userChoice === 'scissors' && computerChoice === 'paper'){return 'You won'} else{return 'error'}               };

const playGame=function(){const userChoice=getUserChoice('rock'); const computerChoice=getComputerChoice();
console.log('You threw: ' + userChoice);
  console.log('The computer threw:' + computerChoice);};

console.log(playGame(determineWinner('rock', 'scissors')));

playGame();
1 Like

no wonder i couldn’t find the mistake, your mistake was in the determine winner function.

the instructions:

inside the playGame() function, call the determineWinner() function

you didn’t call playGame function inside your determineWinner function. What you did, was calling playGame in the determineWinner function call. Which is very different

by doing so, the returned result of determineWinner is passed as argument to playGame, but playGame doesn’t have a parameter. Which i think should just throw an error (parameter and argument mismatch)

i would advise to draw the flow of your program on a piece of paper

1 Like

‎OK, calling the determineWinner function inside the playGame function‎. Would it be this: playGame(determineWinner(‘paper’, ‘rock’););?

Drawing it on a piece of paper(Do you mean I should take a picture after putting it on paper?)‎. Please I would appreciate if you can edit my errors and paste the amended code here.

1 Like

no. You have a function called playGame:

const playGame=function(){
  // the body of the function 
}

in the body of the function, you need to call determineWinner

no, just write down for yourself how the data is passed around in the functions

if that is what you are after, just find the solution online. I am not going to waste my time with that.

1 Like

This will do. Thank you for your time. I’m glad my code was correct.

Sent from my BlackBerry 10 smartphone.

1 Like