JS Functions and Classes

4.A. AIM: Write a JavaScript code to book movie tickets online and calculate the total price based on the 3 conditions: (a) If seats to be booked are not more than 2, the cost per ticket remains Rs. 150. (b) If seats are 6 or more, booking is not allowed. (c) If seats are less than 6 give discount of 10% and calculate the discounted amount.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Book Movie Tickets</title>
</head>
<body>
  <script>
    var noOfTickets = parseInt(window.prompt("Enter number of tickets"))
    BookMovieTickets(noOfTickets)

    function BookMovieTickets(noOfTickets){
      document.write("Price of each ticket : Rs. 150")
      document.write("<br>Number of Tickets : "+noOfTickets)
      var price = noOfTickets*150
      if(noOfTickets<=2){
        document.write("<br>Price is : "+price)
      }else if(noOfTickets>=6){
        document.write("<br>You exceed maximum limit.")
      }else{
        document.write("<br>Price is : "+price)
        document.write("<br>10% Discount : "+price*0.1)
        document.write("<br>Total Price : "+(price - (price*0.1)))
      }
    }
  </script>
</body>
</html>

4.B. AIM: Create an Employee class extending from a base class Person. Hints: (i) Create a class Person with name and age as attributes. (ii) Add a constructor to initialize the values (iii) Create a class Employee extending Person with additional attributes.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Employee Class</title>
</head>
<body>
  <script>
    class Person{
      constructor(name, age){
        this.name = name
        this.age = age
      }
    }
    class Employee extends Person{
      constructor(name, age, salary, address){
        super(name,age)
        this.salary = salary
        this.address = address
      }
      display(){
        document.write("Name : "+this.name)
        document.write("<br>Age : "+this.age)
        document.write("<br>Salary : "+this.salary)
        document.write("<br>Address : "+this.address)
      }
    }
    var emp = new Employee('Govardhan',36,40000,'Ongole')
    emp.display()
  </script>
</body>
</html>