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

186
Views
use mi código de 1 ronda para hacer un juego de 3 rondas "Piedra, papel o tijera" - Javascript

Estoy construyendo un juego de piedra, papel o tijera con Javascript, hice un modo de 1 ronda del juego y funcionó, ahora quiero agregar un segundo modo "al mejor de tres rondas", pero después de probar muchas cosas, mi código se desordenó y no puede averiguar qué hacer exactamente.

trato de agregar un count = 0; count < 3; count = count + 1 pero no sé exactamente dónde ponerlo

¿Puede alguien ayudarme por favor?

 var mode = prompt("Please press 1 for single game mode or 2 for best out of 3 mode"); if (mode === '1') { oneRound; } if (mode === '2') { bestOfThree; } // set Computer Choice var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = "rock"; } else if (computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } // Compare value for oneRound mode var oneRound = function(computerChoice, userChoice) { if (computerChoice === userChoice) { return "The result is tie!"; } if (computerChoice === "rock") { if (userChoice === "scissors") { return "Computer wins"; } else { if (userChoice === "paper") return "Player wins"; } } if (computerChoice === "paper") { if (userChoice === "scissors") { return "Computer wins"; } else { if (userChoice === "rock") return "Player wins"; } } if (computerChoice === "scissors") { if (userChoice === "rock") { return "Computer wins"; } else { if (userChoice === "scissors") return "Player wins"; } } }; console.log("Player Choice: " + userChoice); console.log("Computer Choice: " + computerChoice); console.log(oneRound(computerChoice, userChoice));

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

mira esto

Uso setTimeout para permitir que la pantalla muestre el resultado.

 const play = () => { // set Computer Choice var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = "rock"; } else if (computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } console.log("Player Choice: " + userChoice); console.log("Computer Choice: " + computerChoice); if (computerChoice === userChoice) { return "The result is tie!"; } if (computerChoice === "rock") { if (userChoice === "scissors") { return "Computer wins"; } else { if (userChoice === "paper") return "Player wins"; } } if (computerChoice === "paper") { if (userChoice === "scissors") { return "Computer wins"; } else { if (userChoice === "rock") return "Player wins"; } } if (computerChoice === "scissors") { if (userChoice === "rock") { return "Computer wins"; } else { if (userChoice === "scissors") return "Player wins"; } } }; const round = () => { const res = play(); console.log(res) cnt-- wins[cnt] = res.startsWith("Player") ? 1 : 0; if (cnt === 0) { const total = wins.reduce((a, b) => a + b) console.log(`You beat the computer ${total} time${total===1?"":"s"}`) return } setTimeout(round, 10) // else go again } let cnt = 1, wins = []; const mode = prompt("Please press 1 for single game mode or 2 for best out of 3 mode"); if (mode === '2') { cnt = 3; } round()

about 4 years ago · Juan Pablo Isaza 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!