Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
Rock Paper Scissors Prompt To Ask for Decision to run the game

Hello StackOverflow Community,

I have been studying JavaScript for about 3 days give or take and I have created a rock paper scissor "game" that runs but only with the player decision is added to the code. I wanted to fix this instead so that an prompt alert pops up to ask "Pick Rock, Paper, Scissor Now" and have the game use that input as the deciding factor to who will win. I have ran the code that I have provided and ended up this error:

 a internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'readline-sync'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/tmp/zUokdwLcHz.js:1:20)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3) 

I tried reviewing my spelling and ()/;/, to make sure that they are all correct and I feel like they are. I am sure this is an easy fix so thank you in advance you if you can guide me the correct way.

Here is the code:

const userInput = prompt("What will you shoot")
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
  return userInput;

} else {
  console.log("Error!");
}

const ComputerChoice = () => {
  const randomNumber = Math.floor(Math.random() * 3)
  if (randomNumber === 0) {
    return "rock";
  } else if (randomNumber === 1) {
    return "paper";
  } else {
    return "scissors";
  }
}

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return "Tie, please try again";
  } else if (userChoice === "paper" && computerChoice === "rock") {
    return "Player wins";
  } else if (userChoice === "scissors" && computerChoice === "Paper") {
    return "Player wins";
  } else if (userChoice === "rock" && computerChoice === "scissors") {
    return "Player wins";
  } else if (userChoice === "bomb") {
    return "Player wins"
  } else {
    return "Computer Wins"
  }
}

const playGame = () => {
  const userChoice = getUserChoice('')
  const computerChoice = ComputerChoice()
  console.log("you threw a " + userChoice);
  console.log("The computer threw a " + computerChoice);

  console.log(determineWinner(userChoice, computerChoice));
}

playGame();

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

comment out your first return statement -it's illegal and change getUserInput() at the bottom to just userInput

var userInput = prompt("What will you shoot")
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
  //return userInput;

} else {
  console.log("Error!");
}

const ComputerChoice = () => {
  const randomNumber = Math.floor(Math.random() * 3)
  if (randomNumber === 0) {
    return "rock";
  } else if (randomNumber === 1) {
    return "paper";
  } else {
    return "scissors";
  }
}

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return "Tie, please try again";
  } else if (userChoice === "paper" && computerChoice === "rock") {
    return "Player wins";
  } else if (userChoice === "scissors" && computerChoice === "Paper") {
    return "Player wins";
  } else if (userChoice === "rock" && computerChoice === "scissors") {
    return "Player wins";
  } else if (userChoice === "bomb") {
    return "Player wins"
  } else {
    return "Computer Wins"
  }
}

const playGame = () => {
  const userChoice = userInput//getUserChoice('')
  const computerChoice = ComputerChoice()
  console.log("you threw a " + userChoice);
  console.log("The computer threw a " + computerChoice);

  console.log(determineWinner(userChoice, computerChoice));
}

playGame();

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda