You just need to write your functions inside the script block (between <script>
and </script>
, replacing //JavaScript code goes here
with your code.
You have to define the three functions used in the onclick
events of the buttons.
ClickMe(), Submit() and Reset()
Defining functions in Javascript
- https://www.w3schools.com/js/js_functions.asp
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions
Clickme should get a random element from an array
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
- Getting a random value from a JavaScript array
Maybe you’ll need also some dom manipulation function to add the content of the equation somewhere
Submit() needs to get some input and compare it to the expected result, so you’ll need some input fields on your submit form
- https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms
- https://www.w3schools.com/html/html_forms.asp
Or you should prompt the user to input the answer
- https://www.w3schools.com/jsref/met_win_prompt.asp
- https://www.webnots.com/create-alert-prompt-confirm-dialog-boxes-using-javascript/
As you are checking the answer to be valid. You’ll need to check evaluating the equation exposed and maybe you need eval
but remember
eval is evil
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
- https://javascriptweblog.wordpress.com/2010/04/19/how-evil-is-eval/
Your Reset() function just needs to reload the page
– How to reload a page using JavaScript