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

119
Views
Estaba creando un juego de Simon usando javascript pero recibí un error en la consola:

Por favor, dame la solución para este código . Estaba creando un juego de Simon usando javascript, pero recibí un error en la consola:

El error: Uncaught ReferenceError: randomChosenColour no está definido en game.js:3:20 (anónimo) @ game.js:3

código del archivo index.html:

 <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Simon</title> <link rel="stylesheet" href="styles.css"> <link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet"> </head> <body> <h1 id="level-title">Press A Key to Start</h1> <div class="container"> <div lass="row"> <div type="button" id="green" class="btn green"> </div> <div type="button" id="red" class="btn red"> </div> </div> <div class="row"> <div type="button" id="yellow" class="btn yellow"> </div> <div type="button" id="blue" class="btn blue"> </div> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="game.js"></script> </body> </html>

código del juego.js:

 var buttonColours = ["red", "blue", "green", "yellow"]; var gamePattern = [randomChosenColour]; function nextSequence(params) { var randomNumber = Math.floor(Math.random() * 4); var randomChosenColour = buttonColours[randomNumber]; gamePattern.push(randomChosenColour); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Es porque cuando declaras gamePattern , randomChosenColour aún no está definido .

Solo necesita declarar la matriz gamePattern como una matriz vacía.

 var gamePattern = [];
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!