showing results for - "how to make a button do different functions on different clicks"
Caterina
13 Jul 2018
1<button id="clickme">Click Me</button>
2<script>
3  function one() {
4     alert('one clicked');
5     document.getElementById('clickme').onclick = two;
6  }
7
8  function two() {
9   alert('two clicked');
10  }
11
12  document.getElementById('clickme').onclick = one;
13</script>
Ainsley
10 Aug 2017
1var callOne = true;
2
3function one() {
4   alert('Call one');
5}
6
7function two() {
8   alert('Call two');
9}
10
11function call(){
12   if(callOne) one();
13  else two();
14  callOne = !callOne;
15}
Maeline
12 Nov 2018
1var fn3 = (function() {
2  var first = true;
3  return function() {
4    first ? fn1() : fn2();
5    first = !first;
6  }
7})();
8
9function fn1() {
10  console.log(1);
11};
12function fn2() {
13  console.log(2);
14};