JavaScript Simplified / Chapter 82 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

When defining a method, the parameter in the following code would be replaced by the keyword _____. this.name = name; function function
Complete the line for a method definition in a constructor. this.calcTotal = __________ function() { function\(\){
Code the first line of a method definition in a constructor. The name of the method is displayName this.displayName = function() { this\.displayName=function\(\){
Code the first line of a constructor definition. The name of the constructor is Planet. It has a single parameter, size. function Planet(size) { functionPlanet\(size\){
Code the first line of a method definition in a constructor. Make up the name of the method. this.compare = function() { this\.[a-z_$][a-zA-Z0-9_$]*=function\(\){
Code the first line of a method definition in a constructor. It has two parameters. Make up all the names. this.compare = function(firstContestant, secondContestant); this\.[a-z_$][a-zA-Z0-9_$]*=function\([a-z_$][a-zA-Z0-9_$]*,[a-z_$][a-zA-Z0-9_$]*\);
Code a constructor for an object that has one property and one method. The method displays the value of the property in an alert. Make up the names. Don't forget that the method definition ends with a semicolon. function Holiday(name) {
  this.name = name;
  this.displayName = function() {
    alert(this.name);
  };
}
function[A-Z][a-zA-Z0-9_$]*\(([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]this\.\1=\1;[\r\n]this\.[a-z_$][a-zA-Z0-9_$]*=function\(\){[\r\n]alert\(this\.\1\);[\r\n]};[\r\n]}
Call a constructor to create an object with three string properties. Make up everything. const thirdCat = new Cat("Carmine", "tabby", "9"); const[a-z_$][a-zA-Z0-9_$]*=new[A-Z][a-zA-Z0-9_$]*\(•.*•,•.*•,•.*•\);
  1. I've coded a constructor.
  2. Create a new object using the constructor.
  3. Call the method.
  4. Wait a moment.
  5. If you've coded correctly, an alert will display a string that includes the object's name and age.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 82 in the book.
  1. Click the HTML button to see my markup for an empty paragraph whose ID is "p1".
  2. Click the Result button to see a blank page.
  3. Click the JS button.
  4. Code a constructor that includes a property and a method. The method inserts the value of the property into the empty paragraph whose id is #p1".
  5. Use the constructor to create an object.
  6. Call the method.
  7. If you've coded correctly, the value will be displayed on the page.
  8. For help with this code, see Chapter 82 in the book.