So this is what i have, very simplified version of my code. So basically the 'userinput' function needs to know whether the user clicked on button 'run' or 'hit':
html code:
<button id="run">Run</button>
<button id="hit">Hit</button>
javascript code:
slaying = true;
while(slaying){
//gets user input
userinput();
// continue with the rest of the while loop until slaying is true
}
How would you write userinput()??
Instead of using a function
"userInput()"you can use events and perform the same steps as you would do insideuserInput()You can use the
onclickevent as,And write the below script for this as,
Here is a JSFiddle