0

How to make One Click execute first function and second click execute second function ? ||

Example : I have Power mobile button,,, When we click power button display black screen (" Mean display off ") And Then when we click again power button ,, "display on" 🤔🤔🤔 how can we write this code ?

27th Jan 2021, 3:06 PM
Sajid Ali
Sajid Ali - avatar
7 Réponses
+ 3
https://code.sololearn.com/WkdCAD8TbLcD/?ref=app basic switch handler factory... should handle correctly any number of functions, for any target (onevent attributes, 'event' addEventListener, anything else...) callback functions are filtered (non function arguments are skipped).
27th Jan 2021, 6:54 PM
visph
visph - avatar
+ 1
Use an if statement. if (screen_is_on) { ... code to turn off screen } else { ... code to turn on screen }
27th Jan 2021, 3:21 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
That was just a generic example. For your if condition check the state of something and write the rest of your code accordingly. You can also use a variable such as a boolean that you change the value of within the if statement each time the event happens. If you want more help you have to be specific and share your code in the playground and explain what exactly it is you're trying to do.
27th Jan 2021, 3:29 PM
ChaoticDawg
ChaoticDawg - avatar
0
screen_is_on What i write ?
27th Jan 2021, 3:23 PM
Sajid Ali
Sajid Ali - avatar
0
As i use display : non/block
27th Jan 2021, 3:23 PM
Sajid Ali
Sajid Ali - avatar
0
visph its working,, But out of mine understand 😅!
28th Jan 2021, 3:13 AM
Sajid Ali
Sajid Ali - avatar