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

132
Views
Use varios botones con valor, cuando se hace clic en ellos se guardan en una matriz
<button id="option1" onclick="b1" value=1 >1</button> <button id="option2" onclick="b2" value=2>2</button> <button id="option3" value= 3>3</button> <button id="option4" value= 4 >4</button> <button id="option5" value= 5>5</button> <button id="option6" value= 6>6</button> <button id="revolver">shoot</button> <div id="div1"></div>

JavaScript:


 const array1 = []; const doc = document; let health = 3; let revy = doc.getElementById("revolver"); let bullet1 = doc.getElementById("option1"); let bullet2 = doc.getElementById("option2"); let bullet3 = doc.getElementById("option3"); let bullet4 = doc.getElementById("option4"); let bullet5 = doc.getElementById("option5"); let bullet6 = doc.getElementById("option6");

lo que quiero hacer es agregar una función que, cuando se hace clic, también conocida como bullet1.onclick = function something. pero no sé cómo usar este valor más adelante, ya que uso array1.push(bullet1.value) en una función como se ve a continuación.

 bullet1.onclick = function(){ array1.push(bullet1.value) console.log(array1) //when clicked it returns the [1] and ads every time clicked } console.log(array1) //returns []

¿Cómo puedo usar este valor [1] más tarde? también conocido como fuera de la función más tarde? ¿Necesito una función específica o una función de flecha como let b = () => {} b = "something i can use the array for" y uso onclick en el botón o function myfunction(){} function();


Por cierto, estoy planeando crear varias de esas funciones como la anterior, por lo que puedo usar el último valor para combatir un bot que uso. TAMBIÉN, este es un método que quiero probar, ya que intento guardar todos los valores de los botones cada vez que se hace clic en cada uno de ellos. y luego puedo usarlo más tarde. iban a guardar todos los clics en una matriz. entonces usaré el último valor en la matriz para combatir un bot.


Espero que entiendan, si tienen alguna pregunta a qué me refiero, puedo tratar de ser mejor explicando

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!