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

272
Views
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
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!