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.