how do you call a function in javascript until two buttons are clicked before the fuction executes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

how do you call a function in javascript until two buttons are clicked before the fuction executes?

click on two buttons before the function is called

16th Mar 2021, 2:20 PM
Francis Woli
Francis Woli - avatar
4 Answers
+ 1
var flag1, flag2; btn1.onclick = () => { flag1 = true; if (flag2) myfunc(); }; btn2.onclick = () => { flag2 = true; if (flag1) myfunc(); };
16th Mar 2021, 3:09 PM
visph
visph - avatar
+ 1
Francis Woli obviously, you need to reset both flags (in function called or in if block) to false for enabling multiple calls...
16th Mar 2021, 4:53 PM
visph
visph - avatar
0
PSEUDOCODE ----------------------- btn1.onClick keyOne = true btn2.onClick keyTwo = true if(keyOne && keyTwo) callYourFunction()
16th Mar 2021, 2:29 PM
Akib
Akib - avatar
0
how do apply it to event listeners?
16th Mar 2021, 2:36 PM
Francis Woli
Francis Woli - avatar