JavaScript Simplified / Chapter 81 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

A function that creates objects is a (one word)_______ constructor constructor
Fill in the blank. Make up the name. (Remember the naming convention for this type of function. function _______(name, area, population) { The first character is capitalized: Nation not nation [A-Z][a-zA-Z0-9_$]*
The constructor's name is Student. Fill in the blank to call it. const student404 = ____________("Sigel", "Efrem", 12, 89); new Student newStudent
The name of the constructor is Planet. Code the first line of the function, including the parameters distance and mass. function Planet(distance, mass) { functionPlanet\(distance,mass\){
The name of the constructor is Planet. Code the complete function, including the parameters distance and mass. The property names are the same as the parameter names. function Planet(distance, mass) {
  this.distance = distance;
  this.mass = mass;
}
functionPlanet\(distance,mass\){[\r\n]this\.distance=distance;[\r\n]this\.mass=mass;[\r\n]}
Code a constructor function that has a single parameter. The property name is not the same as the parameter name. Make up all the names. function Patient(x) {
  this.age = x;
}
function[A-Z][a-zA-Z0-9_$]*\(([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]this\.[a-z_$][a-zA-Z0-9_$]*=\1;[\r\n]}
Create an object by calling a constructor named Product. Include two arguments, the product's name and the product's color. Make up everything except the constructor function name. const sku2191 = new Product("frisbee", "white"); const[a-z_$][a-zA-Z0-9_$]*=newProduct\(•.*•,•.*•\);
Code a constructor function with two parameters. The names of the parameters and the names of the properties are the same. Make up everything. function Vehicle(make, model) {
  this.make = make;
  this.model = model;
}
function[A-Z][a-zA-Z0-9_$]*\(([a-z_$][a-zA-Z0-9_$]*),([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]this\.\1=\1;[\r\n]this\.\2=\2;[\r\n]}
  1. I've coded a constructor.
  2. Use the constructor to create an object.
  3. Display the value of one of the properties of the object in an alert.
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the property value.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter in the book.
  1. Code a constructor that creates objects that have three properties. Give the properties different names from the parameter names.
  2. Call the constructor.
  3. Display the value of one of the properties in an alert.
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the property value.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter in the book.