ReferenceError: приглашение не определено - камень, бумага или ножницы - PullRequest
0 голосов
/ 20 мая 2018

У меня возникли некоторые проблемы при завершении этого кода.

ReferenceError: приглашение не определено в Object.//(/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:1:80) это первая ошибка, я старался не использовать подсказку, а просто вызывал код в конце, но мне нужен совет поКакова лучшая практика для этого?

Может ли кто-нибудь дать советы по улучшению этого кода?

let userPrompt = prompt("enter a choice: ");

const getUserChoice = userPrompt => {
  if (userInput === 'rock' || userInput === 'Paper' || userInput === 'scissors') {
    return userInput;
  } else {
    console.log('Error');
  }
}

const randomNumber = 'Math.floor(Math.random() * 3)';
switch (randomNumber) {
  case 0:
    return 'rock';
    // I don't know if I have to have a break here.
  case 1:
    return 'Paper';

  case 2:
    return 'scissors';

  case 3:
    return 'bomb';

}
console.log(getUserChoice());

function determineWinner(userChoice, computerChoice) {
  if (userChoice === computerChoice) {
    return 'the game is a tie';
  }
  if (userChoice === 'bomb') {
    return 'You won!'; /* add a fourth condition that checks if the userInput is 'bomb'.At the beginning of determineWinner(), add another if statement that makes the user win if the userChoice is 'bomb'.*/
  }
  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return 'The computer won!';
    } else {
      return 'You won!';
    }
  } else if (userChoice === 'Paper') {
    if (computerChoice === 'rock') {
      return 'The user won';
    } else {
      return 'The computer won';
    }
  } else if (userChoice === 'Scissors') {
    if (computerChoice === 'Paper') {
      return 'The user won';
    } else {
      return 'The computer won';
    }
  }
}

console.log(determineWiner('rock', 'paper'));
console.log(determineWiner('paper', 'rock'));
console.log(determineWiner('scissors', 'paper'));

const playGame = () => {
  const userChoice =
        getUserChoice('scissors');
  const computerChoice =
        getComputerChoice();
  console.log(`you threw: ${userChoice}`);
  console.log(`The computer threw: ${computerChoice}`);
  console.log(determineWinner(userChoice, computerChoice));
};



playgame();
...