Question

Please help! Create a web application in HTML & JavaScript that contains an updated "math quiz"....

Please help!

Create a web application in HTML & JavaScript that contains an updated "math quiz". Include the following:

  1. The quiz should implement the addEventListener method of responding to events.
  2. Questions should change when the page is refreshed
    1. Questions could be generated using the Math.random() function.
    2. Questions could be generated from an array of questions.
  3. Answers to quiz questions should be checked as right or wrong.
  4. A running score should be kept of the questions answered correctly/incorrectly and displayed within the web page.
  5. If users type in non-numerical input they should be prompted to try again.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//SAVE THE CODE AS filename.html

<!DOCTYPE html>
<html>
<head>
   <title>Math Quiz</title>
</head>
<style type="text/css">
   body {
          
  
}
</style>
<script type="text/javascript">

       // Function is called when the page loads or refreshed
       function mathQuiz() {

       // Array of Questions Declared
       var qnArray = [
                        "What is 1+2?",
                       "What is 5*7",
                       "What is 10/5",
                       "What is 1+2+6?",
                       "What is 9-5?",
                       "What is 1+7-2?",
                       "What is 4*4?"
                       ];

       // Random Question is selected and stored in randomQn variable
       var randomQn = qnArray[Math.floor(Math.random()*qnArray.length)];

       // Answer Entered by User is stored in enteredAns variable
       var enteredAns = prompt(randomQn);

       // Checks if the Entered answer is Number or not
       if(!isNaN(enteredAns)) {

           // if random Question Selected matches with this one, then is true
           if(randomQn === "What is 1+2?" ) {

               // If Question matches, then checks for answer
               // if answer is right the Shows right Answer else shows Wrong Answer
               // All the Below conditions are checked one by one
               if(enteredAns === "3" ) {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }

           if(randomQn === "What is 5*7") {
              
               if(enteredAns === "35") {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }

           if(randomQn === "What is 10/5") {
              
               if(enteredAns === "2" ) {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }
           if(randomQn === "What is 1+2+6?") {
              
               if(enteredAns === "9" ) {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }
           if(randomQn === "What is 9-5?") {
              
               if(enteredAns === "4" ) {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }
           if(randomQn === "What is 1+7-2?") {
              
               if(enteredAns === "6" ) {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }
           if(randomQn === "What is 4*4?") {
              
               if(enteredAns === "16" ) {

                   alert("Right Answer");
               }
               else {
                   alert("Wrong Answer");
               }
           }

       }
       else {
           alert("Enter Numbers only");
       }
}
</script>

<body onload="mathQuiz()">
   <br> <center>
<h1>Refresh Page to get Question</h1>
   </center>
</body>

</html>  

SCREENSHOTS:

Add a comment
Know the answer?
Add Answer to:
Please help! Create a web application in HTML & JavaScript that contains an updated "math quiz"....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT