Java Reference
In-Depth Information
exercise 3 Solution
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 5, Question 3</title>
</head>
<body>
<script>
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.getFullName = function () {
return this.firstName + " " + this.lastName;
};
Person.prototype.greet = function (person) {
alert("Hello, " + person.getFullName() +
". I'm " + this.getFullName());
};
var johnDoe = new Person("John", "Doe");
var janeDoe = new Person("Jane", "Doe");
johnDoe.greet(janeDoe);
</script>
</body>
</html>
Save this as ch5 _ question3.html .
This is a simple matter of replacing the createPerson() function with the Person reference type
you defined at the end of Chapter 5.
To create your Person objects, you use the new operator when calling the Person constructor
function, passing in the first and last names of the people you want to represent.
Chapter 6
exercise 1 Question
What problem does the following code solve?
var myString = "This sentence has has a fault and and we need to fix it."
var myRegExp = /(\b\w+\b) \1/g;
myString = myString.replace(myRegExp,”$1”);
Search WWH ::




Custom Search