<div>
<h2 id="prompt">
You come across a fork in the road. Do you go left or right?
</h2>
<div id="leftAndRightbuttons">
<button type="button" onclick="goLeft()">Go Left</button>
<button type="button" onclick="goRight()">Go Right</button>
</div>
<div id="riverOptions" style="display: none">
<button type="button" onclick="swimAcross()">Swim Across</button>
<button type="button" onclick="startOver()">Turn Around</button>
</div>
<button type="button" id="startOverButton" onclick="startOver()" style="display: none">START OVER</button>
</div>
<script>
//Left and right buttons:
function goLeft() {
document.getElementById("prompt").innerText = "You come across a river.";
document.getElementById("leftAndRightbuttons").style.display = "none";
document.getElementById("riverOptions").style.display = '';
}
function goRight() {
document.getElementById("prompt").innerText = "You come across a bog.";
document.getElementById("leftAndRightbuttons").style.display = "none";
var x = 2;
if(x == 2){
alert();
}
}
//River options:
function swimAcross()
{
document.getElementById("prompt").innerText = "You drowned. Game Over.";
document.getElementById("riverOptions").style.display = 'none';
document.getElementById("startOverButton").style.display = '';
}
function startOver()
{
document.getElementById("prompt").innerText = "You come across a fork in the road. Do you go left or right?";
document.getElementById("leftAndRightbuttons").style.display = '';
document.getElementById("riverOptions").style.display = "none";
document.getElementById("startOverButton").style.display = 'none';
}
</script>
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.