Discount Price Calculation in Javascript


Create a web page which calculates the discount for the product for the specific season. The seasons with their discount rates are summer (10%), new year (5%) and clearance (15%). The discount is calculated on the price of the product. The web page should look like

Quiz for exam - Discount Price Calculation
Quiz for exam – Discount Price Calculation

The outcome webpage should look as

Quiz for exam - Discount Price Calculation1
Quiz for exam – Discount Price Calculation1

The client side validation is performed using JavaScript.

Web page Requirements

          The web page background color should be #99FFFF. The label “Discount Price” should be a heading tag(h1) and should be italic bolded, centered, and in color code #b03060.

Product name – a text box with the name “name”, should not be empty, contain only alphabets and space and mandatory field.

Price – a number box with the name price, mandatory field and the minimum value should be greater than 15000.

Season is a drop down box with tag name “season”. The drop down box will have the following value and display value

·         summer           –           SUMMER SALE

·         newyear          –           NEW YEAR SALE

·         clearance        –           CLEARANCE SALE

The table should be left aligned with 35% and an outer border style of solid 5px and 30% border width. The space between element and the border must be 10px.

            A submit button with left aligned with 45% and with a value “GET DISCOUNT PRICE” should be present and name should be submit. Once submit, the web page calculates the discounted price for the product.

            The outcome must be displayed in 2 div tags, where the first will have the id named “discount” and is to display the discount % of the product and the second will have the id named “result” and is to display the discounted price of the product. Both the div tags should be center aligned with bold text. The font of the discounted price must be italic, #FF0000 and 40px size and for discount % it is 25px. Have separate styles for div, discount and result

 Note: Make sure all tags and attributes are in lower case



<!DOCTYPE html>
                font-style: italic;
                font-weight: bold;
                text-align: center;
                color: #b03060;
                margin-left: 35%;
                border-style: solid 5px;
                border-width: 30%;
                padding: 10px;
                border-style: solid;
                border-width: 2px;
                float: left;
                width: 45%;
                margin-left: 45%;
                text-align: center;
                font-weight: bold;
                font-style: italic;
                color: #FF0000;
                font-size: 40px;
                font-size: 25px;
    <body style="background-color:#99FFFF;">
        <h1>DISCOUNT PRICE</h1>
                    <td>Product Name</td>
                    <td><input type="text" name="name" id="name" pattern="[a-zA-Z0-9 ]+" required> </td>
                    <td>Product Price</td>
                    <td><input type="number" name="price" min="15001" id="price" required></td>
                        <select name="season" id="season">
                        <option value="summer">SUMMER SALE</option>
                        <option value="newyear">NEW YEAR SALE</option>
                        <option value="clearance">CLEARANCE SALE</option>
            <input type="submit" value="GET DISCOUNT PRICE" id="submit" name="submit" onclick="discount()">
        <div id="discount"></div>
        <div id="result"></div>
            function discount(){
                var p=document.getElementById("price").value;
                var s=document.getElementById("season").value;
                var d;
                    document.getElementById("discount").innerHTML="The discount is 10%";
                else if(s=="newyear"){
                    document.getElementById("discount").innerHTML="The discount is 5%";
                else if(s=="clearance"){
                    document.getElementById("discount").innerHTML="The discount is 15%";
                document.getElementById("result").innerHTML="The discounted price : Rs "+d;


Leave a Comment

Your email address will not be published. Required fields are marked *