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

130
Views
Use multiple buttons with value, when clicked they save to an array
<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");    

what i want to do is to add a function that when clicked aka bullet1.onclick = function something. but i dont know how to use this value later as i use array1.push(bullet1.value) in a function as seen under.

 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 []

how can i use this [1] value later? aka outside the function later? do i need a specific function or arrow function like let b = () => {} b = "something i can use the array for" and use onclick in the button orfunction myfunction(){} function();


BTW im planning to create multiple of those functions like the one above, so i can use the last value to combat a bot i use. ALSO this is a method i wanna try as im trying to save all the buttons values each time each of them is clicked. and then i can use it later. were gonna save all the clicks into an array. then ill use the last value in the array to combat a bot.


hope you understand, if you guys have any questions what i mean i can try be better at explaining

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!