In: Computer Science
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."
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: