Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Piedra, papel o tijera Indicación para pedir la decisión de ejecutar el juego

Hola comunidad de StackOverflow,

He estado estudiando JavaScript durante aproximadamente 3 días más o menos y he creado un "juego" de piedra, papel o tijera que se ejecuta pero solo se agrega al código con la decisión del jugador. En su lugar, quería arreglar esto para que apareciera una alerta emergente que preguntara "Elige piedra, papel o tijera ahora" y que el juego usara esa entrada como el factor decisivo para decidir quién ganará. Ejecuté el código que proporcioné y terminé con este 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)

Traté de revisar mi ortografía y ()/;/, para asegurarme de que todos son correctos y siento que lo son. Estoy seguro de que esta es una solución fácil, así que gracias de antemano si me puede guiar de la manera correcta.

Aquí está el código:

 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 answers
Answer question

0

comente su primera declaración de devolución: es ilegal y cambie getUserInput () en la parte inferior a solo entrada de usuario

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!