Currently, I am involved in a project that involves generating random variables to create unique scenes. One specific variable is the location of these scenes. My goal is to be able to generate a location with just one button click. Subsequently, by pressing another button, I should be able to generate a new location. Furthermore, upon clicking on the initial button, I would like to retrieve the previously generated location associated with that specific button press.
function locationGenerator()
{
var locations = ["movie", "park", "garden", "home"];
var location = locations[Math.floor(Math.random()*locations.length)];
document.getElementById('location').innerHTML="<h2>Location</h2>" + location;
Below are the buttons utilized to execute the codes:
<button type="button" onclick="introFunction()">intro</button>
<button type="button" onclick="midFunction()">mid</button>
To keep track of whether a button has been pressed more than once, I have implemented this code snippet:
function introFunction(){
if (introClicked == 1){
document.getElementById('introClicked').innerHTML="<div id=location></div>";
}
else{
document.getElementById('introClicked').innerHTML="<div id=location></div>";
locationGenerator();
introClickedFunction();
}
Additionally, the value of introClicked is updated through this function:
var introClicked = 0;
function introClickedFunction(){
introClicked = introClicked + 1;
}
Unfortunately, despite implementing the above function, no data is returned upon pressing the button twice.