Question

In: Computer Science

Javascipt Assignment: Create a document that includes a constructor function named Company in the document head...

Javascipt Assignment:

Create a document that includes a constructor function named Company in the document head area.

Include four properties in the Company object definition:

name, products, motto, and numEmployees (for number of employees.)

Instantiate a new Company object in the document body , then assign values to each of the properties

Print the name, products, motto, and the numEmployees properties to the screen using document.write methods.

Combine each printed property with a descriptive string.

For example, when you print the company name, it should read something like " The company name is MyComany."

Solutions

Expert Solution

Here is code:

<script>

// class company

function Company(name, products, motto, numEmployees) {

this.name = name;

this.products = products;

this.motto = motto;

this.numEmployees = numEmployees;

}

// Object for the company

var c = new Company("MyComany", "Pen", "NO #1 company", 2500);

// Display the data

document.write("The company name is " + c.name + "<br>");

document.write("The products name is " + c.products + "<br>");

document.write("The motto of the company is " + c.motto + "<br>");

document.write("The no. of Employees are " + c.numEmployees + "<br>");

</script>

Sample code to test with html:

<!doctype html>

<html>

<head>

<title>Company</title>

<script>

// class company

function Company(name, products, motto, numEmployees) {

this.name = name;

this.products = products;

this.motto = motto;

this.numEmployees = numEmployees;

}

// Object for the company

var c = new Company("MyComany", "Pen", "NO #1 company", 2500);

// Display the data

document.write("The company name is " + c.name + "<br>");

document.write("The products name is " + c.products + "<br>");

document.write("The motto of the company is " + c.motto + "<br>");

document.write("The no. of Employees are " + c.numEmployees + "<br>");

</script>

</head>

<body>

<h1></h1>

</body>

</html>

Output:


Related Solutions

- Create a java class named SaveFile in which write the following: Constructor: The class's constructor...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor should take the name of a file as an argument A method save (String line): This method should open the file defined by the constructor, save the string value of line at the end of the file, and then close the file. - In the same package create a new Java class and it DisplayFile in which write the following: Constructor: The class's constructor...
Create a class named BankAccount, containing: a constructor accepting a String corresponding to the name of...
Create a class named BankAccount, containing: a constructor accepting a String corresponding to the name of the account holder. a method, getBalance, that returns a double corresponding to the account balance. a method withdraw that accepts a double, and deducts the amount from the account balance. Write a class definition for a subclass, CheckingAccount, that contains: a boolean instance variable, overdraft. (Having overdraft for a checking account allows one to write checks larger than the current balance). a constructor that...
Java program Create a constructor for a class named Signal that will hold digitized acceleration data....
Java program Create a constructor for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp data The constructor...
VBA In this assignment you will create a Word Macro-Enabled Document. The document will contain procedures...
VBA In this assignment you will create a Word Macro-Enabled Document. The document will contain procedures with the following declarations: • Sub Main() • Sub GetGrades(grades() As Integer, total As Integer) • Sub CreateOutput(className As String, grades() As Integer, total As Integer) The Main sub-procedure will be the macro that initializes the task. In this procedure you will declare all necessary variables, prompt the user to enter the name of the class and the number of students, resize the grades...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
This assignment includes the creation of a text document using Vi Editor and changing permissions to...
This assignment includes the creation of a text document using Vi Editor and changing permissions to access the new file. Use Vi Editor to create a text document Add data to your text file Save your text file Exit Vi Editor Display the contents of your file using the following tools: cat head tail Set file permissions as listed below User – RWX Group – RWX Other – RWX Use a GUI tool to display the new file in your...
Create a function named ‘dividing’. This function will take one parameter value, which will be an...
Create a function named ‘dividing’. This function will take one parameter value, which will be an integer. For the function you will use ‘Exception Handling’ with the use of the try and except statements to try and return the results of a number divided by the parameter value given to the function. If the parameter passed to the function is the integer value of zero then your function should return ‘You tried to divide by zero!’ through the use of...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
Create a function named getCreds with no parameters that will prompt the user for their username...
Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below: # Administrator accounts list adminList = [ { "username": "DaBigBoss", "password": "DaBest" }, { "username": "root", "password": "toor" } ] Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT