Page 158 - Computer Software Application TP - Volume 1
P. 158
COMPUTER SOFTWARE APPLICATION - CITS
3 Save the program as a .html file
4 Open the html file with a web browser
5 Go to the browsers console tab and verify the output.
III Using Classes
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Classes </title>
</head>
<body>
<script>
// ES6 class for creating person objects
class Person {
constructor(firstName, lastName, age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
fullName() {
return this.firstName + “ “ + this.lastName;
}
}
// Creating a new instance of Person
let person2 = new Person(“Jane”, “Smith”, 25);
// Accessing object properties and methods
console.log(person2.firstName); // Output: Jane
console.log(person2.lastName); // Output: Smith
console.log(person2.age); // Output: 25
143
CITS : IT & ITES - Computer Software Application - Exercise 40 CITS : IT & ITES - Computer Software Application - Exercise 40