+ 2

Can you change parts of code with other code

I want to make it that if I press button a function x is called, if I press button b and after that button a again function y is called. But it shouldn't be solved with an if...then...else syntax. Any ideas or is the problem unclear?

26th Jul 2017, 4:56 PM
Jack
Jack - avatar
6 Answers
+ 4
I would create a boolean and set it to true when I press a. Then, if b is pressed and this boolean is true, the other function is executed. But you will need at least an if statement or as mentioned by @Frank a ternary operator.
26th Jul 2017, 6:53 PM
Drax
Drax - avatar
+ 2
'Shouldn't be solved with if,then,else syntax' If this is like a homework assignment you could use a tenary operator as a stand in for if/else statement. Whats the need for this restriction? More detail would be useful.
26th Jul 2017, 5:37 PM
Frank Gunsch
Frank Gunsch - avatar
+ 1
button a calls function x button b along with button a call function y right?
26th Jul 2017, 5:30 PM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
0
@Drax I thought of that myselfe, I'm just a relative newbee so I thought there would be a better way to solve the problem. But thanks.
26th Jul 2017, 7:37 PM
Jack
Jack - avatar
- 1
Look at PHP. I don't know of a way in Javascript.
26th Jul 2017, 5:00 PM
josh mizzi
josh mizzi - avatar
- 1
what I think.. is...since you want a button to call the function...then assign the function to the button...just like you assign a link to an image.. when you click the image.. the link loads.. right???
26th Jul 2017, 5:07 PM
Otumian Empire
Otumian Empire - avatar