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

You can't return multiple values with multiple variables, but you can do it with an _____. (5 characters) array array
In the following code, x could be the name of a regular variable, but it is an array name if the function returns an ______. const x = someFunction(); array array
Fill in the blank to return both multiples. function returnMultiples() {
  let firstMultiple = 2 * 2;
  let secondMultiple = 4 * 4;
  return ____________;
}
[firstMultiple, secondMultiple] \[firstMultiple,secondMultiple\]
Fill in the blank to assign the first element in the array to firstMultiple. let bothMultiples = returnMultiples();
let firstMultiple = ______________
bothMultiples[0]; bothMultiples\[0\];
Code a three-line function with no parameters that returns two string values. Make up everything. function returnStrings() {
  return ["Hello ", "world!"];
}
function[a-z_$][a-zA-Z0-9_$]*\(\){[\r\n]return\[•.*•,•.*•\];[\r\n]}
Code two lines. The first line calls a function with no parameters that returns an array. The second line assigns the second array element to a variable. Remember that the preferred keyword for an array is const. Make up everything. const anArray = someFunction();
let secondValue = anArray[1];
const([a-z_$][a-zA-Z0-9_$]*)=[a-z_$][a-zA-Z0-9_$]*\(\);[\r\n]let[a-z_$][a-zA-Z0-9_$]*=\1\[1\];
Code a single line that calls a function (no arguments) and assigns two values returned by the function to an unnamed array. Remember that the preferred keyword for an array is const. Make up everything. const [firstValue, secondValue] = someFunction(); const\[[a-z_$][a-zA-Z0-9_$]*,[a-z_$][a-zA-Z0-9_$]*\]=[a-z_$][a-zA-Z0-9_$]*\(\);
Code a function (no parameters) that assigns integers to two variables, then returns the two integers to the calling code by specifying the variables. Make up everything. function returnNumbers() {
  let x = 1;
  let y = 2;
  return [x , y];
}
function[a-z_$][a-zA-Z0-9_$]*\(\){[\r\n]let([a-z_$][a-zA-Z0-9_$]*)=[-]?(?:[.]\d+|\d+(?:[.]\d*)?);[\r\n]let([a-z_$][a-zA-Z0-9_$]*)=[-]?(?:[.]\d+|\d+(?:[.]\d*)?);[\r\n]return\[\1,\2\];[\r\n]}
  1. Code a function with two parameters.
  2. Use the parameter names to create an array.
  3. Return the array.
  4. Code a function call that passes two arguments and assigns the results of the function to an array.
  5. Code an alert that displays the value of the second element.
  6. Click the Result button (or, after revising, don't click, just wait).
  7. Wait a moment.
  8. If you've coded correctly, an alert will display the value of the second element.
  9. Dismiss the alert by clicking OK.
  10. For help with this code, see Chapter 51 in the book.
  1. In three lines, code a function with two parameters.
  2. The function does nothing but return both parameter values.
  3. Call the function with two integer arguments.
  4. Display the second element in an alert.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, an alert will display the second element.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 51 in the book.