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");
}
}