This part of a question I asked on here last week. It was answered, except now I'm going to use this function multiple times, and instead of repeating the function multiple times I want to use arguments/parameters, but there are issues....
html:
<button id="button1">a</button>
<button id="button2">b</button>
javascript:
var funcAPressed = false;
var funcA = function(x, y) {
alert(x);
y = true;
alert(y);
};
var funcB = function(x, y) {
if (funcAPressed === false){
alert(x);
}
else{
alert(y);
}
};
var buttonA = document.getElementById('button1');
buttonA.addEventListener('click', function(){funcA("Button A has been pressed", funcAPressed);});
var buttonB = document.getElementById('button2');
buttonB.addEventListener('click', function(){funcB("press Button A", "Button B has been pressed");});
Here's how this is all set up: I want the user to press the buttons in the correct order, A then B. if B is pressed first, there's an alert message. The answer I got from my previous question on here was to create a boolean and set it to false, which I did at the top. When I click the button, I get the alert message below, and it looks like funcAPressed becomes true since I did the alert(y) which alerts "true."
The problem is that when I click button B after clicking Button A, it still sees funcAPressed = false instead of it being true.
The funcB will work fine if instead of y = true I have funcAPressed = true...but by doing that I'll have to copy this function multiple times in my document instead of only being able to use it once and assign parameters.