Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda