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

280
Views
Javascript: ¿Crear y llamar variables dinámicas?

Tengo un script que contiene 3 preguntas. Empecé creando 3 variables (ej: var q1 = "pregunta aquí") y tengo una función que elige aleatoriamente un número entre 1 y 3 y elige esa pregunta (var pregunta = "q" + rand;) pero si quiero hacer referencia a esta variable llamada pregunta para generar la pregunta en HTML (p. ej., document.getElement.Id("output").innerHTML += question;) ¿cómo lo haría?

Aquí está mi código:

 // Questions List var q1 = " Question 1 here" var q2 = "Question 2 here" var q3 = "Question 3 here" // Randomly generate a question and then output it var randy = Math.floor(Math.random()*3+1); var question = "q" + randy; document.getElementById("output").innerHTML += question;
 <!doctype html> <html> <body> <div id="output"></div> </body> </html>

Entonces, básicamente, el script elegirá una pregunta del 1 al 20 y la enviará a mi etiqueta HTML div.

Lo siento si esto no está claro. Cualquier ayuda es muy apreciada.

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