There is a simple generator ( link to codepen ). How to hide the "ask" button after the alert and show the "new"?
function GetValue() { var myarray = new Array("word1","word2","word3"); var random = myarray[Math.floor(Math.random() * myarray.length)]; document.getElementById("message").innerHTML=random; }; //rand array element var clicks = 0; function onClick() { clicks += 1; document.getElementById("clicks").innerHTML = clicks; printMessage(document.getElementById("message").innerHTML,clicks); }; //count clicks function printMessage(random, clicks) { if (random === "word1") { document.getElementById("alert").innerHTML = "wow, after " + clicks + " clicks"; } } //display "you get word1 after _ clicks" function myFunction() { location.reload(); } //reload <body> <textarea id="message" rows="1"></textarea> <input type="button" id="btnSearch" value="ask" onclick="GetValue();onClick()" /> <p>attempts: <a id="clicks">0</a></p> <p id="alert"></p> <button id="reload" onclick="myFunction()">new</button>
if (random === "word1")hide one button and show the other. I understood correctly? And now you have both buttons displayed - is this how it was conceived? - Anton Shchyrov