Chapter 6 Part I Review

  1. Using an object literal, create a variable named rabbit that holds a reference to an Object that has a property named name which is set to the String Peter and a property named height which is set to 42.
  2. Write a statement that sets the name field of the variable rabbit to “Roger“.
  3. Write a statement using dot notation that prints the height of the rabbit.
  4. Write a statement using [] notation that prints the height of the rabbit.
  5. Create an array named items that holds the following values: 22, “hello”, and {a: 10}.
  6. Declare an array named grades and initialize it with the values 85, 93, 79, 98, 100.
  7. Use the from method on the array named grades to create a new array named curvedGrades so that each grade in curvedGrades is 5 more than the respective value in grades.
  8. Using a single statement, create an array named holy that has two elements, one at index 1 with a value 10 and one at index 3 with a value 20.
  9. What are the values of the elements at index 0 and 2 in the array named holy?
  10. Suppose a variable named cow is initialized to the value 7. Is the following statement a legal expression? holy[cow] = 3;
  11. What method can use use to determine if a variable holds a reference to an Array?
  12. Suppose an array named names has been declared and initialized with a set of student names. Write a statement that declares a variable named indices that holds an array of the valid indices for the array named names.
  13. Write a statement that declares a variable named pairs that holds key/value pairs for each index/name pair in names.
  14. Write a statement that declare an array named bigArray that holds 100 integers.
  15. Write a statement that prints to the console the contents of the array named names with ” hush now ” separating the names.
  16. List the element on a stack starting at the top, after the following operations have been executed? push(1), push(2), pop(), push(3)
  17. List the elements on a queue starting at the top, after the following operations have been executed? push(1), push(2), shift(), push(3)
  18. Suppose an array named ages holds a set of integers. Write a statement using the sort method that sorts the value from largest to smallest.

© 2020, Eric. All rights reserved.