Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda