Open In App

Multiplication Quiz Webapp using HTML CSS and JavaScript

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will see how to create a multiplication quiz web app using HTML, CSS, and JavaScript.

Description of Web App: In this web app, random questions come one by one based on basic multiplication. If you give a correct answer, then it will increment by +1, and if you give the wrong answer, then it will decrement by -1.

File Structure: There are three files index.html (HTML file), design all the elements of a webpage using style.css (CSS File) and give all logical functionality by script.js (JavaScript file).

  • index.html
  • style.css
  • script.js

Prerequisite

Approach

HTML file:

  • Create one container class in which all the elements are present.
  • Inside the container create a form and remove the action attribute.
  • The form provides questions and score headings with one input field for user answers and a “Submit” button.

CSS File:

JavaScript file:

  • Create two variables to store the random number using a math object. In question, add these two numbers by JavaScript innerText property. Also, store the answer of these 2 random numbers in one variable.
  • If the user clicks on the “Submit” button, it compares the user’s answer and the correct answer. If both are equal, then increment score by +1 other wise decrement score by -1.
  • Add score in local storage by using the localstorage.getItem() method.
HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multiplication Quiz WebApp</title>

    <link rel="stylesheet" href="style.css">

</head>

<body>
    <div class="container">
        <h1>GeeksforGeeks</h1>
        <h3><b> Multiplication Quiz App </b></h3>
        <form id="form">
            <p id="score">score : 0</p>
            <h1 id="question">What is X Multiply of X?</h1>
            <input type="number" id="inp" placeholder="Enter Your Answer" 
                   autofocus autocomplete="off">
            <button id="btn" type="submit">Submit</button>
        </form>
    </div>

    <script src="script.js"></script>
</body>
</html>
CSS JavaScript

Output:

a1

Next Article

Similar Reads

three90RightbarBannerImg