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

110
Views
trying to increment simon game level in javaScript

I am new to javaScript and trying to create a simon game in jS and want to increase level everytime nextSequence() is called

var started = false; //toggler
var level = 0;
$(document).on("keydown", function() {
  if (!started) {
    $("h1").text("Level 0")
    nextSequence()

    started = true;
  }
})


function nextSequence() {
  var randomNumber = Math.random() * 4;
  randomNumber = Math.floor(randomNumber);
  var randomChosenColor = buttonColors[randomNumber] //any one color
  gamePattern.push(randomChosenColor);

  $("#" + randomChosenColor).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100); // animate
  level = level + 1
  console.log(level)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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

0

Assuming you have all of the necessary variables set (buttonColors). The variable level should be increased by one every key down, if you want to display the score through the h1 you would need to incorporate the 'score' variable into the text

so change $("h1").text("Level 0") to $("h1").text("Level " + level)

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!