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

150
Views
¿Cómo cambio la cantidad de movimientos del juego para las diferentes dificultades del juego?

Soy muy nuevo en Javascript y he hecho un juego de piedra, papel o tijera. El juego en sí funciona pero nunca termina. He intentado agregar varios grados de dificultad permitiendo diferentes movimientos por nivel de dificultad. Sin embargo, ahora no tengo ideas sobre cómo hacer esto. He intentado algunas cosas diferentes y ahora estoy completamente atascado, cualquier otra cosa que parezca intentar solo hace más un desastre. Cualquier ayuda sería apreciada,

Gracias

 function selectDifficulty() { let difficultyRating = ["easy", "normal", "hard"]; let easyMoves = 7; let normalMoves = 5; let hardMoves = 3; if (difficultyRating == "easy") { movesCounter = easyMoves; } else if (difficultyRating == "hard") { movesCounter = hardMoves; } else movesCounter = normalMoves; document.getElementById("moves-counter").innerHTML = movesCounter; }
 <!-- choose difficulty --> <div class="difficulty-area"> <h2>Choose Difficulty</h2> <button onclick="selectDifficulty('easy')" class="btn btn-easy" aria-label="Easy Difficulty"> <p id="easy">Easy</p> </button> <button onclick="selectDifficulty('normal')" class="btn btn-normal" aria-label="Normal Difficulty"> <p id="medium">Normal</p> </button> <button onclick="selectDifficulty('hard')" class="btn btn-hard" aria-label="Hard Difficulty"> <p id="hard">Hard</p> </button> </div> <!-- moves remaining until game over --> <div class="moves-remaining"> <p> Moves remaining : <span id="moves-counter">0</span> </p> </div>

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

0

Las llamadas a su función usan parámetros, pero la definición de su función no los detecta.

Agregue un parámetro a la definición de la función (y elimine la matriz ahora desaparecida), y su código funcionará.

 function selectDifficulty(difficultyRating) { let easyMoves = 7; let normalMoves = 5; let hardMoves = 3; if (difficultyRating == "easy") { movesCounter = easyMoves; } else if (difficultyRating == "hard") { movesCounter = hardMoves; } else movesCounter = normalMoves; document.getElementById("moves-counter").innerHTML = movesCounter; }
 <!-- choose difficulty --> <div class="difficulty-area"> <h2>Choose Difficulty</h2> <button onclick="selectDifficulty('easy')" class="btn btn-easy" aria-label="Easy Difficulty"> <p id="easy">Easy</p> </button> <button onclick="selectDifficulty('normal')" class="btn btn-normal" aria-label="Normal Difficulty"> <p id="medium">Normal</p> </button> <button onclick="selectDifficulty('hard')" class="btn btn-hard" aria-label="Hard Difficulty"> <p id="hard">Hard</p> </button> </div> <!-- moves remaining until game over --> <div class="moves-remaining"> <p> Moves remaining : <span id="moves-counter">0</span> </p> </div>

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!