How do I get my clear button to work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I get my clear button to work

I am trying to use the button tag to clear my text and p tag. But it seems not doing anything https://code.sololearn.com/Wp4525OEqABE/?ref=app

4th May 2023, 4:24 PM
kingSab
kingSab - avatar
18 Answers
0
just call the compare function from inside of the randnum function. In other words, add to line 14: compare();
4th May 2023, 7:51 PM
Orin Cook
Orin Cook - avatar
+ 1
I didn't see where to add my code snippet so y'all know what I'm talking about.
4th May 2023, 4:24 PM
kingSab
kingSab - avatar
+ 1
clear button is working fine for me, might be an app issue on your end compare isn't doing anything, though, cause you only call it once when the page loads
4th May 2023, 6:34 PM
Orin Cook
Orin Cook - avatar
+ 1
as I said, you're only calling it once, at window.onload, so it runs once when the page loads (before the user has a chance to input anything) and then you just never call it. add a compare() call to the end of randnum or something
4th May 2023, 6:41 PM
Orin Cook
Orin Cook - avatar
+ 1
oh, also having tried that: you shouldn't ask for arguments for compare(), and the else if can just be an else
4th May 2023, 6:46 PM
Orin Cook
Orin Cook - avatar
+ 1
kingSab There is no input type="string". if you want numbers, use type ="number" Since you are only guessing a few numbers, my suggestion is to use buttons instead of input. It is easier to use and the game would be more fun to play. Also, changing the number everytime makes it harder to win. Maybe a higher or lower hint is given and the player gets multiple tries would be better? If the player constantly loses, it is very easy to lose interest in the game.
4th May 2023, 10:07 PM
Bob_Li
Bob_Li - avatar
0
Yes I got it fixed. Now it's the compare code. Can you elaborately make me understand where I'm wrong here.
4th May 2023, 6:37 PM
kingSab
kingSab - avatar
0
4th May 2023, 6:37 PM
kingSab
kingSab - avatar
0
Orin Cook when you say add compare to random, is it as an argument or what? I am struggling to understand that.
4th May 2023, 6:58 PM
kingSab
kingSab - avatar
0
Orin Cook thanks a lot. It worked. Will add some other functionalities and maybe little CSS. Is there any social media acct that I can follow you?
4th May 2023, 7:57 PM
kingSab
kingSab - avatar
0
Hello Bob_Li , thanks for the suggestions, everything is working just fine now. I just need to figure out how to give the player 3 chances, break to loop if he guess it right
4th May 2023, 10:28 PM
kingSab
kingSab - avatar
0
kingSab you could add a try counter.
4th May 2023, 10:36 PM
Bob_Li
Bob_Li - avatar
0
Bob_Li yes I'm working on that
4th May 2023, 10:39 PM
kingSab
kingSab - avatar
0
Pls i need help
5th May 2023, 10:13 AM
Israel Akpan
Israel Akpan - avatar
0
Israel Akpan where do you need help? Share you problem and code on your question tab and someone will help you.
5th May 2023, 10:21 AM
kingSab
kingSab - avatar
0
What is input or c
5th May 2023, 10:43 AM
Israel Akpan
Israel Akpan - avatar
0
How can I get curve corner in my button?
5th May 2023, 12:23 PM
Zion
Zion - avatar
0
Raj Grover what is curve corners? ...this {}?
5th May 2023, 12:38 PM
kingSab
kingSab - avatar