Class Using return Methods
<html><head>
<title> Class Using return Methods</title>
<script>
class Person
{
constructor(firstName, lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
greet()
{
let theGreeting = "Howdy " +
this.firstName + " " + this.lastName;
return theGreeting;
}
bye()
{
let theSalutation = "Bye " +
this.firstName + " " + this.lastName;
return theSalutation;
}
}
function displayIt(where, whichOne) //DISPLAY
{
document.getElementById(where).innerHTML = whichOne;
}
let david = new Person("David","Thompson");
</script>
<body>
<button onclick="displayIt('div1', david.greet())"> GREETING
</button>
<button onclick="displayIt('div2', david.bye())"> SALUTATION
</button>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
<title> Class Using return Methods</title>
<script>
class Person
{
constructor(firstName, lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
greet()
{
let theGreeting = "Howdy " +
this.firstName + " " + this.lastName;
return theGreeting;
}
bye()
{
let theSalutation = "Bye " +
this.firstName + " " + this.lastName;
return theSalutation;
}
}
function displayIt(where, whichOne) //DISPLAY
{
document.getElementById(where).innerHTML = whichOne;
}
let david = new Person("David","Thompson");
</script>
<body>
<button onclick="displayIt('div1', david.greet())"> GREETING
</button>
<button onclick="displayIt('div2', david.bye())"> SALUTATION
</button>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>