Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you make a button do something different after a certain number of times of clicking it?
    primarykey
    data
    text
    <p>I'm coding a text adventure and I haven't done Javascript in a while, and I want the "Feel around the cave" button in my code to go to "d" the second time clicking it. How do I do this? Here's my current code:</p> <pre><code>&lt;script&gt; function one() { var newButton1 = '&lt;button id="btnTwo" onclick="two()" &gt;Pick up stick&lt;/button&gt;'; var newButton2 = '&lt;button id="btnThree" onclick="three()"&gt;Leave it there&lt;/button&gt;'; document.getElementById("a").innerHTML="You feel something on the ground, and you think it's a stick."+newButton1+newButton2; } function two() { document.getElementById("b").innerHTML="You pick up the stick. It might be useful for something."; document.getElementById("btnTwo").style.display = 'none'; document.getElementById("btnThree").style.display = 'none'; } function three() { document.getElementById("c").innerHTML="You leave the stick on the ground and continue on."; document.getElementById("btnTwo").style.display = 'none'; document.getElementById("btnThree").style.display = 'none'; } function four() { document.getElementById("d").innerHTML="You find another stick stuck to the wall with something that feels like honey. You can also feel some rocks stuck to the wall next to it."; } &lt;/script&gt; &lt;div style="margin-left:15px; width:200px; margin-top:100px;"&gt; &lt;button onclick="one()"&gt;Feel around the cave&lt;/button&gt; &lt;/div&gt; &lt;div id="entire" style="margin-left:490px; margin-top:-22px; width:400px; height:600px;&gt; &lt;div id="d"&gt;&lt;/div&gt; &lt;div id="c"&gt;&lt;/div&gt; &lt;div id="b"&gt;&lt;/div&gt; &lt;div id="a"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload