Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
How to pass boolean values as paramters thorugh addeventlistener js

I have different buttons and depending on what button is pressed, i want the variables in my function to change.

css:

.build{
    border-radius:50%;
    height:85px;
    width:85px;
    position:absolute;
    background-color: transparent;
    cursor: pointer;
    border: 1px solid transparent;
}
#build1{
    margin-left:372px;
    margin-top:320px;
    
}

html:

<button class="build" id="build1"></button>

Rest is javascript

Some variables

var build1EL=document.querySelector("#build1");
var buildtower1=false;
var click1=false;
var a1=false;
var mynter=100;
build1EL.addEventListener("click",clicktower);

A function

function clicktower(){

if(byggtaarn1===false){
    if(coins>=75){
        coins-=75;
        byggtaarn1=true;
        a1=true;
    }
}
if(click1===true){
    click1=false;
    a1=false;
}
if(a1===true){
    click1=true;
}
tower1();
a1=true;
}

Then this works perfectly fine, tower1() is another function and the inside of the function is kinda messy, but it works. But i must do this 5 more times, but with different buttons and a corresponding buildtower, click and a-variable

So keeping the same variables for the first button, and change the function and addeventlistener to this:

build1EL.addEventListener("click", function(){ clicktower(buildtower1, click1,a1); });

function clicktower(buildtower,click,a){

if(buildtower===false){
    if(coins>=75){
        coins-=75;
        buildtower=true;
        a=true;
    }
}
if(click===true){
    click=false;
    a=false;
}
if(a===true){
    click=true;
}
taarn1();
a=true;}

But this doesnt work, i tried different ways to get the addeventlistener to work with arguments, but none worked.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda