In this section of code, I’m trying to define ‘weaponselector’ as a certain value based on which button is clicked. this is a pretty basic question and I’m sure the result is just to change the function to a variable or something simple like that, but I’ve been stuck on it for a bit.
let wepo1=1;
let wepo2=2;
let wepo3=3;
let wepo=0;
function weaponselector {
}
document.querySelector("button[name='shotgun/parent']").addEventListener("click",function() {
weaponselector(wepo + wepo1);
});
document.querySelector("button[name='pistol']").addEventListener("click",function() {
weaponselector(wepo+wepo2);
});
document.querySelector("button[name='rifle']").addEventListener("click",function() {
weaponselector(wepo+wepo3);
(The addition of some later code that references the ‘weaponselector’ function
there may be something wrong with this code too, and feel free to help me with that if you’d like too. I’m new to using JS so I’m having a lot of pretty explainable errors)
if (weaponselector=1){
let weapon="shotgun" === {
weapondamage:20
};
}
if (weaponselector=2) {
let weapon="pistol" === {
weapondamage:5
};
}
if (weaponselector=3) {
let weapon="rifle" === {
weapondamage:10
};
}