+ 1

Math question in "confirm" and "prompt" JavaScript

I am trying to basically have the user input information to answer some math questions. Pretty much like a quiz, but confirmed by JavaScript coding. I figured a Confirm code may be easy, that way I ask one question at a time and it can return true or false based on the coding of JavaScript. 1. Is there possibly an easier way? 2. How do I get the confirm box to possibly state "True or False" or "Yes or No" instead of "Ok or Cancel"? 3. How do I get the users input double checked by coding in JavaScript? example: Prompt box asks to type in a number, then the user inputs the information as far as mathematics is concerned. How do I have the code check the user inputs accuracy? such as 1-1=? and the user inputs 0. How do I have it check the information for being true? If and Else coding? 4. If I use "If and Else" coding, how do I use that with Prompt boxes and Confirm boxes?

29th Nov 2017, 3:35 PM
Howard Eugene Patrick Jr
Howard Eugene Patrick Jr - avatar
3 ответов
+ 4
1. Easier way would be to create a form on the page that has your questions/inputs/etc... Disable how the form would normally submit, and add buttons next to each answer input box so when the user clicks submit, it'll check the answer and then return as either correct or incorrect. You could even have a little section that's next to the question where you can display a green check or red x depending on if they got it right. This would make the quiz easier to work with, and you wouldn't have to deal with popups/page refreshing. You can do a lot more on the actual webpage than you can from a prompt box. 2. To the best of my knowledge, you can't change those buttons on a confirm box. However, if you're comfortable with using jQuery, they have a lot of useful features in regards to dialog boxes, and you could easily accomplish this task with it. 3. You could do something like: var userInput = prompt("Enter first number or whatever..."); ^userInput now stores the user input. Use that variable to do your double checking/validation. If it's valid, display as correct or whatever. If it's invalid, inform use they got it wrong. You can use simple IF checks for that, or create a function that'll help with all of the validation and then just feed over the appropriate data to it, such as the question type, question variables, and the user's input. 4. var userInput = prompt("Enter number:"); var userConfirmed = confirm("Do you confirm?"); ^That'll store their values. For prompt, it'll store user's input. For confirm, it'll store as true or false (boolean).
29th Nov 2017, 3:55 PM
AgentSmith
+ 1
What is 144+144=?<br> <input type="radio" name="" value="288" />288<br /> <input type="radio" name="" value="287" />287 <br /> <input type="submit" value="Submit"/> Ok, how do I have the user click on 288 or 287, then when they hit submit I check wether the answer is true or false? Perhaps there is an easier way? Right now, if you click on submit nothing happens. Do I have to have an input syntax or onSubmit syntax? Should I run an If/Else statement?
29th Nov 2017, 10:58 PM
Howard Eugene Patrick Jr
Howard Eugene Patrick Jr - avatar
0
Good point with the form version of the quiz. I was hoping to ask a few questions with prompt, alert, or confirm. However, I may switch to a quiz about 10 questions long so I guess I could use "form." A few questions wouldn't have been bad with alert, prompt, or confirm, but if I can not customize it too much without learning Jquery then I will use a different method. I appreciate your help, it was a very good answer. I suppose I will make the quiz longer since I can not customize the alert, prompt, and confirm. I might as well if I go through all the trouble of a form. Thank you.
29th Nov 2017, 6:48 PM
Howard Eugene Patrick Jr
Howard Eugene Patrick Jr - avatar