[x] On page load, execute 'getRandomNumber' function and store the returned value on a constant to work with it later.
[x] If you call 'getRandomNumer' function inside the event callback, you will be creating a new random number each time the user clicks the button. That makes the game really complex and the hints will not have sense. Let's generate the random number when the page loads instead.
[x] Define the logic to make the counter work
[x] Remember to convert input value string to a number
[x] Use ONE addEventListener for each event. If you need to execute multiple functions at once perhaps you can call them inside your unique handler
You are close to the exercise solution, but here you have a steps guide to complete it anyway ;)
Save a reference to DOM elements in variables
Generate the random number and save it to a variable
Init counter of trials to 0
Define a function that executes when the user clicks on the button, that
increments the counter and paints its value in the HTML
collect the value of the HTML input and compare it with the random number
if they are equal, draw a 'You Win' message
if it's lower, draw a 'Too short' message
if it's higher, draw a 'Too long' message
Assign a listener to the button click to execute the previous function
Then you can improve the game as you please, here you have some ideas:
Add new feedback when the number is bigger than 100 or smaller than 0.
Manage when the user hits the button and the input is empty.
Make the input work when hitting enter key.
Add a reset button that cleans the input, the counter, writes the initial feedback and generates a new random number to play again!
Really cool job @VictoriaDiro !!!
Here you have some tips to improve the exercise:
addEventListener
for each event. If you need to execute multiple functions at once perhaps you can call them inside your unique handlerYou are close to the exercise solution, but here you have a steps guide to complete it anyway ;)
Then you can improve the game as you please, here you have some ideas:
Let me know if you have any doubts ;)
Go for it!!