Question

Need a Javascript program for an Employee class with a Constructor Function. It must contain properties...

Need a Javascript program for an Employee class with a Constructor Function. It must contain properties of name, annualsalary and bonus of multiple employee of a company. It should contain a Method for calculateBonus. The bonus will be 20% of annualsalary. When the calculateBonus method is called, the bonus should be returned as the bonus's return value. Create a Function Called checkEmployee(). This Function when called will instantiate an employee Object Will Call the Employee's calculateBonus Method and when the Bonus is Returned, will use a simple javascript alert to display the name, annualSalary and their bonus.

<body>

<Input type="button" onclick="checkEmployee();">Check</Input>

</body>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<html>
   <head>
      <script type = "text/javascript">
       
            class Employee
        {
     constructor(name,annualSalary,Bonus)
      {
     this.name=name;
     this.annualSalary=annualSalary;
     this.Bonus=Bonus;
     }
     calculateBonus(annualSalary,Bonus)
     {
      alert(this.name,this.annualSalary,this.Bonus);
      return (annualSalary*this.Bonus)/100;
     }
     }
      checkEmployee()
   {
  
var emp = new Employee('chandana',100000,20);
   emp.calculateBonus(this.annualSalary,this.Bonus);
    }

   </script>
   </head>

   <body>
      <p>Click the following button to call the function</p>
     <form>
         <input type = "button" onclick = "checkEmployee()" value = "Call Function">
      </form>
        </body>
</html>

Add a comment
Know the answer?
Add Answer to:
Need a Javascript program for an Employee class with a Constructor Function. It must contain properties...
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
  • Could you please help me write a Javascript code that will show a smiley face picture...

    Could you please help me write a Javascript code that will show a smiley face picture when I click the button. The picture should not display until the button is pressed. Here is my attempt at the code. It does not work. Please keep the code as simple as you can as I am new to coding. Please also use the <div> tag if possible, onclick and use the getElementById. Thank you <html> <body> <img id="exampleImage" src="smileyFace.png" /> <button onclick="pushButton()">Try...

  • Write a javascript file Create an object constructor (using new and function ) to hold a...

    Write a javascript file Create an object constructor (using new and function ) to hold a recipes information. It has to include properties for title (a string), servings (a number), and ingredients (an array of strings). It also has to have a method called print(nOfServings). in your app, create a single object using this contractor and call its print method On separate lines (a Document.write() statement for each), log (display on console) the recipe information so it looks like: myObj.print(2)...

  • Need help with these scenarios Question 1 Write a JavaScript program to get the volume of...

    Need help with these scenarios Question 1 Write a JavaScript program to get the volume of a Cylinder with four decimal places using object classes. Volume of a cylinder : V = πr2h where r is the radius and h is the height of the cylinder. Your solution must include an HTML and a JavaScript file, with a button to create the cylinder, inputs for the cylinder's radius and height and an output to show the cyclinder's volume. Your solution...

  • JavaScript expert, I need your help : My program doesn't work. I have the following program,...

    JavaScript expert, I need your help : My program doesn't work. I have the following program, it is simple web page: Create an object called person with name = John, age = 50. Then, access the object to display "John is 50 years old”. I have written some code here. Hint: Create an object with the var keyword, followed by a name and an "=" sign. Put the properties and values inside the {}; signs Note: Use getElementById() and innerHTML...

  • In an external JavaScript file, you need to create two global variables for the Quarter name...

    In an external JavaScript file, you need to create two global variables for the Quarter name array and the Sales amount array. Create an anonymous function and connect it to the onclick event of the Add to Array button that adds the values from the fields (Quarter and Sales) to the respective arrays. Create an anonymous function and connect it to the onclick event of Display Sales button displays the contents of the arrays, displays the sum of all the...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • Build a class called Account.java. This class should have the following properties: AcctNo, Owner and balance....

    Build a class called Account.java. This class should have the following properties: AcctNo, Owner and balance. Also add the appropriate set and get methods, display method and main method. Main() should be used to test this class. In main() instantiate an Account object, fill it with data using the set methods, then call display to display the data.

  • QUESTION 35 When you've created a data structure like this ____. var rect = {length: 9,...

    QUESTION 35 When you've created a data structure like this ____. var rect = {length: 9, width: 6}; you have created a direct instance of an object you have created an object using a custom constructor function you have created an object literal you have created an array literal QUESTION 38 "Once a web page has finished loading, then the ____ event handler fires." loaded onload complete done the language using in javascript QUESTION 29 You have this form. Assume...

  • Write a program using OOP to contain the following methods. Use proper constructor and instantine different...

    Write a program using OOP to contain the following methods. Use proper constructor and instantine different object to use the specified ,methods. The program must be interactive. A method called “displayCourse” which displays the name of CS courses offered in Loudoun. (CS200..) Set Coursename() Display Course time() Display Course name()\ HInt: Course info a=new courseInfo() a.displayCourseTime(name, …) Course name - CSC 200 , time 9;30 am CSC 201 time : 9:30 am

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
ADVERTISEMENT