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

244
Views
A way to add parameters to variables or something so I don't spam functions and vars

So the point of this, game like, website JavaScript is creating triggers. The Const pgUnlock is the on and off switch. I want it so that when the viewer clicks on a button, I will change the element to turn the false into a true. For example, below, it checks if the number 1 is in the [0] index and if it is, it'll unlock a new part of the website, by replacing the # with the next page link. The function 'alertbox()' checks this and if the trigger isn't on, it'll make a button visible, letting the player know that the "page is locked". So my question is how do I add parameters to consolidate the code so I'm not creating 5 more 'alertbox()' functions because the 'check' var has to be customized for each placement for 'pgUnlock'. If not, I'm fine with repeating the code, I just want to see if I/we can keep everything performance friendly by using cleaner code, as I'm not that familiar with JavaScript. To let you know how dumb I am, one of my tries was: 'var check(x,y)= pgUnlock.includes(x,y);'

var a = document.querySelector('.rebtn[href="#"]');
const pgUnlock= [0,0,0,0,0];
var check= pgUnlock.includes(1,0);
var check2= pgUnlock.includes(2,0);
var check3= pgUnlock.includes(3,0);
var check4= pgUnlock.includes(4,0);
var check5= pgUnlock.includes(5,0);

if (check==true) {
  a.setAttribute('href', './introPage.html');
} 

reBtn.onclick=()=>{
    alertbox();
}

legBtn.onclick=()=>{
    alertbox();
}

godBtn.onclick=()=>{
    alertbox();
}

chgBtn.onclick=()=>{
    alertbox();
}

ch2Btn.onclick=()=>{
    alertbox();
}

function alertbox(){
    if(check==false){
        alertBtn.classList.add("visalert");
    }
}
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!