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

Fill in the blank for a class constructor. class Nation {
  ___________(name, area, population) {
constructor constructor
Fill in the blank for a class constructor. ______ Nation {
  constructor(name, area, population) {
class class
Convert this line to the first two lines of a class definition. function Person(name, age) { class Person {
  constructor(name, age) {
classPerson{[\r\n]constructor\(name,age\){
Code the first two lines of a class constructor. The constructor's name is Planet. It has one parameter, size. class Planet {
  constructor(size) {
classPlanet{[\r\n]constructor\(size\){
Code a class constructor that has a single parameter. Make up everything. class Planet {
  constructor(size) {
    this.size = size;
  }
}
class[A-Z][a-zA-Z0-9_$]*{[\r\n]constructor\(([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]this\.\1=\1;[\r\n]}[\r\n]}
Fill in the blanks to complete this class constructor, adding a method. The method returns the sum of this.width and this.height. Make up the name of the method. class Dimensions {
  constructor(width, height) {
    this.width = width;
    this.height = height;
  }
  _________
    ________________________________
  _
_
sumEm() {
    return this.width + this.height;
  }
}
[a-z_$][a-zA-Z0-9_$]*\(\){[\r\n]returnthis\.width\+this\.height;[\r\n]}[\r\n]}
Code a class constructor that has one parameter and a method that does nothing. Assign the parameter value to a variable the usual way. Make up everything. class NotMuch {
  constructor(color) {
    this.color = color;
  }
  doNothing() {
  }
}
class[A-Z][a-zA-Z0-9_$]*{[\r\n]constructor\(([[a-z_$][a-zA-Z0-9_$]*)\){[\r\n]this\.\1=\1;[\r\n]}[\r\n][a-z_$][a-zA-Z0-9_$]*\(\){[\r\n]}[\r\n]}
Code a class constructor named Person with two string parameters, firstName and lastName. It has a method. The method concatenates the two values, adding a space between them, returning the string. Make up the name of the method. class Person {
  constructor(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
  combine() {
    return this.firstName + " " + this.lastName;
  }
}
class[A-Z][a-zA-Z0-9_$]*{[\r\n]constructor\(firstName,lastName\){[\r\n]this\.firstName=firstName;[\r\n]this\.lastName=lastName;[\r\n]}[\r\n][a-z_$][a-zA-Z0-9_$]*\(\){[\r\n]returnthis\.firstName\+••\+this\.lastName;[\r\n]}[\r\n]}
  1. Code a class constructor that has two parameters, weight and height.
  2. The constructor assigns weight to this.weight and height to this.height.
  3. Use the class constructor to create an object.
  4. Display one of the values in an alert.
  5. Wait a moment.
  6. If you've coded correctly, an alert will display a property value.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 89 in the book.
  1. Code a class constructor that has two parameters, height and weight.
  2. The constructor also has a method that returns weight divided by height.
  3. Use the class constructor to create an object.
  4. Call the method, displaying the returned value in an alert.
  5. Wait a moment.
  6. If you've coded correctly, an alert will display the returned value.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 89 in the book.