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

263
Views
Cómo pasar valores booleanos como parámetros a través de addeventlistener js

Tengo diferentes botones y dependiendo de qué botón se presione, quiero que cambien las variables en mi función.

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>

El resto es javascript

algunas variables

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

Una función

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

Entonces esto funciona perfectamente bien, tower1() es otra función y el interior de la función es un poco desordenado, pero funciona. Pero debo hacer esto 5 veces más, pero con diferentes botones y una torre de construcción correspondiente, haga clic y una variable

Entonces, manteniendo las mismas variables para el primer botón, cambie la función y agregue eventlistener a esto:

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

Pero esto no funciona, probé diferentes formas de hacer que addeventlistener funcione con argumentos, pero ninguna funcionó.

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!