Rock Paper Scissors draw

Hello…

I am getting draw in the console every time, what is the problem?

const getUserChoice = userInput =>{ userInput = userInput.toLowerCase(); if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){ return userInput; } else{ console.log("Error"); } } const getComputerChoice = () =>{ let compChoice; let randomNum = Math.floor(Math.random() * 3); switch(randomNum){ case 0: compChoice = 'rock'; break; case 1: compChoice = 'paper'; break; case 2: compChoice = 'scissors'; break; } return compChoice; } let userChoice = getUserChoice('paper'); let computerChoice = getComputerChoice(); checkDraw = (userChoice, computerChoice) => { if(userChoice === computerChoice){ return true; }else{ return false; } } determineWinner = (userChoice) =>{ if(checkDraw() === true){ return 'The game is draw'; }else{ //if the user choose rock and we are checking against all possible if(userChoice === 'rock'){ if(computerChoice === 'scissors'){ return 'user wins'; }else{ return 'computer wins'; } } //if the user choose scissors and we are checking against all possible if(userChoice === 'scissors'){ if(computerChoice === 'paper'){ return 'user wins'; }else{ return 'computer wins'; } } //if the user choose papaer and we are checking against all possible if(userChoice === 'paper'){ if(computerChoice === 'rock'){ return 'user wins'; }else{ return 'computer wins'; } } } } console.log(determineWinner('paper', 'rock'));

the first debug step would be to log the variables used in the comparison:

checkDraw = (userChoice, computerChoice) => {
  console.log(userChoice, computerChoice);
  if(userChoice === computerChoice){
    return true;
  }else{
    return false;
  }
}

which gives us undefined for both variables, which are equal to each other

1 Like

the problem was that I am not passing arguments in checkDraw when calling

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.