Super Quiz

  1. Declare a variable named arr that holds an array of 3 objects. Each object should holds information about a book and should contain a property named title that holds a string and a property named date_published that holds a number. Feel free to make up the data for the 3 objects.
  2. Write a function named printArray that takes an array as an argument and prints to the console the objects in the array, including each of the object’s properties and values. You may not simply pass the array to console.log.
  3. Write a function named insert that takes an array, a string, and an integer as arguments. The function should create a new object with title and date_published properties and set the property values using the string and integer that are passed into the function. The function should then add the new object to the array that was passed into the function.
  4. Add a new object using the insert function to the array that you created for problem 1. Call the printArray function to verify the new object is in the array.

Chapter 10 Review

  1. Create a function declaration named sumPair that returns the sum of the two arguments that are passed into it.
  2. Initialize two variables and pass them to sumPair. Print the result.
  3. Create a function expression named sumTriple that returns the sum of the three arguments that are pass to it.
  4. Initialize three variables and pass them to sumTriple. Print the result.
  5. Create an arrow function named sumQuad that returns the sum of the four arguments that are passed into it.
  6. Initialize four variables and pass them to sumQuad. Print the result.
  7. Create a function declaration named sumAll that returns the sum of the values in its arguments property.
  8. Call sumAll, passing to it 5 numbers. Print the result.
  9. Create a function named max that allows any number of arguments and returns the maximum value of the arguments that are passed into it. Set the first parameter’s default value to undefined, so that if no arguments are passed to max, undefined is returned.
  10. Call max with no arguments. Print the result.
  11. Call max with 3 arguments. Print the result.
  12. Declare an array named values that holds the values 2,4,6,8, and 10. Call max using the spread operator on values.
  13. Declare a function named min that allows any number of arguments and returns the minimum value of the arguments that are passed into it. Use a rest parameter to hold the values that are passed into the method. Return undefined if no arguments are passed to the function.
  14. Call min with no arguments. Print the result.
  15. Call min with 3 arguments. Print the result.

Chapter 6 Part II Review

For the following problems assume you have the following arrays.

 
let primary = ["red", "blue", "yellow"];  
let secondary = ["green", "purple", "orange"];
let all = ["red", "blue", "yellow", "green", "purple", "orange"];
let objArray = [{name: "joe", score: 21}, {name: "shea", score: 22}, {name: "al", score: 19}];
  1. Create an empty array named items.
  2. Create an array named allColors that contains all of the colors in the arrays named primary and secondary.
  3. Create an array named colorSets that contains 2 elements. The first element being the array named primary and the second element being the array named secondary.
  4. Use the array named all to create an array named favs which contains only the elements with indices between (inclusively) between 1 and 4.
  5. Modify the array named all to include the first element of all, the color “black”, followed by the last element of all.
  6. Write a statement that creates a variable named idx and sets it equal to index of the first occurrence of the string “black” in an array named all.
  7. Write a statement that uses find and stores in a variable named o the first object in objArray that has score greater than 20.
  8. Write a statement that uses filter to create an array named winners that contains all of the objects in objArray that have scores greater than 20.
  9. Write a statement that creates a variable named over and sets it to true if every score in objArray is greater than 20, and sets over to false otherwise.
  10. Write a statement that sets over to true if some score in objArray is greater than 20, and sets over to false otherwise.
  11. Write a statement that uses map to create an array of the scores in objArray.
  12. Write a statement that uses forEach to print to the console the names in objArray that are associated with scores that are greater than 20.
  13. Write a statement that uses reduce to compute the largest score in the array named objArray and stores the value in a variable named max.

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.

Chapter 5 Review

  1. How is a particular date and time actually stored in a Date object?
  2. Declare a variable named now that holds a reference to a Date object representing the current date and time.
  3. Declare a variable named final that holds a reference to a Date object representing 1:30pm on April 24, 2020.
  4. What are the three primitive wrapper types?
  5. Primitive variables do not have methods, yet we can invoke methods on primitive variables. What is the JavaScript engine doing in order to accomplish this?
  6. Suppose a variable named mean has the value 76.3245. Provide a statement that prints to the console the value in mean with only 1 digit after the decimal point.
  7. Suppose a variable named name has the value “Joe Block”. Provide a statement that prints to the console the number of characters in name.
  8. Provide a statement that prints to the console the last character of the String in the variable named str.
  9. What are the three methods used to create substrings from strings?
  10. Suppose a string named course has the value “CSCI-240”. Write a statement that uses one of the substring methods to stores in a variable named num the numeric part of the course (“240”).
  11. Write a statement that uses a string method to store in a variable named loc the index of the first instance of “S” in the string course.
  12. What type of value is returned from startsWith(), endsWith(), and includes()?
  13. What do trim(), trimLeft(), and trimRight() do?
  14. Write a fragment of code that uses a string iterator and a while loop to print to the console the characters in the string “hello”, one on each line.
  15. Write a single statement that uses the destructuring operator to print to the console the characters in the string “hello”, one on each line.
  16. What variable holds a reference to the Global object?
  17. Write a fragment of code that returns a random number between 1 and 20.

Chapter 4 Review

  1. Variable types can be categorized into 2 groups. What are the names of the 2 groups?
  2. Declare an object named obj with a property named age that is set to 20.
  3. Are arguments passed by reference, passed by value, passed by object, or passed by name?
  4. What is the scope chain?
  5. What is the purpose of the with() statement?
  6. What is the scope for variables that are declared with var?
  7. What is the scope for variables that are declared with let?
  8. What is the scope for variables that are declared with const?
  9. What is one of the most common and easily fixed type of memory leak?