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

158
Views
How do I change amount of game moves for different game difficulties?

I'm very new to Javascript and have made a game of rock paper scissors. The game itself works but is never ending. I have attempted to add varying degrees of difficulty by having different moves allowed per difficulty setting. However I'm now out of ideas on how to do this. I have tried a few different things and am now completely stuck, anything else I seem to try just makes more of a mess. Any help would be appreciated,

Thanks

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

Your function calls use parameters, but your function definition doesn't catch them.

Add a parameter to the function definition (and remove the now defunct array), and your code works.

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!