JavaScript Simplified / Chapter 84 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 to check whether the object has the property status. let hasStatus = ______ in flight44; "status" •status•
Fill in the blank to check whether the object flight44 has the property. let hasStatus = "status" ________; in flight44 inflight44
Check whether the object loris has the property cuteness and assign the result to the variable hasProperty, which hasn't been declared beforehand. let hasProperty = "cuteness" in loris; lethasProperty=•cuteness•inloris;
Check whether the object loris has the method measureSpeed() and assign the result to the variable hasMethod, which hasn't been declared beforehand. let hasMethod = "measureSpeed" in loris; lethasMethod=•measureSpeed•inloris;
Check whether an object has a particular property and assign the result to a variable that hasn't been declared beforehand. Make up everything. let result = "color" in shape11; let[a-z_$][a-zA-Z0-9_$]*=•.*•in[a-z_$][a-zA-Z0-9_$]*;
Below is an empty array. Loop through the properties of an object, adding each property in turn to the array. Make up everything except the array name. const props = []; for (let aProp in thing12) {
  props.push(aProp);
}
for\(let([a-z_$][a-zA-Z0-9_$]*)in[a-z_$][a-zA-Z0-9_$]*\){[\r\n]props\.push\(\1\);[\r\n]}
Check whether a property exists that is not inherited, and assign the result to a variable, which hasn't been declared beforehand. Make up all the names. let result = thing12.hasOwnProperty("height"); let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\.hasOwnProperty\(•.*•\);
If a property exists, assign an integer value to it. Make up everything. if ("points" in thing12) {
  thing12.points = 5;
}
if\(•([a-z_$][a-zA-Z0-9_$]*)•in([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]\2\.\1=(0|-?[1-9][\d]*);[\r\n]}
  1. I've coded a constructor. Create an object using the constructor.
  2. Code a prototype property for the constructor.
  3. Check whether the object has that property. If so, display an alert confirming it.
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the confirmation that the object has the property.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 84 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 to see my constructor and empty array.
  4. Create an object using the constructor.
  5. Loop through the properties of the object, adding each property in turn to the array.
  6. Insert one of the array elements into the empty paragraph whose ID is "p1".
  7. If you've coded correctly, the array element will be displayed on the page.
  8. For help with this code, see Chapter 84 in the book.