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

The keyword that sends data back to the calling code is ______. return return
A function returns a value to a ________. variable variable
Code a statement that passes the value of total back to the calling code. return total; returntotal;
Call the function shorten(). Include one argument, aString. Assign the returned value to an undeclared variable, clip. let clip = shorten(aString); letclip=shorten\(aString\);
Code a function with two number parameters. The function returns the result of the parameters multiplied by each other. Code the function in three lines. Make up all the names. function multiply(num1, num2) {
  return num1 * num2;
}
function[a-z_$][a-zA-Z0-9_$]*\(([a-z_$][a-zA-Z0-9_$]*),([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]return\1\*\2;[\r\n]}
Call a function with two arguments that are variables. Make up all the names. concat(str1, str2); [a-z_$][a-zA-Z0-9_$]*\([a-z_$][a-zA-Z0-9_$]*,[a-z_$][a-zA-Z0-9_$]*\);
Code a statement that returns the concatenation of two parameters. Make up the parameter names. return string1 + string2; return[a-z_$][a-zA-Z0-9_$]*\+[a-z_$][a-zA-Z0-9_$]*;
Code a function with 2 parameters. If the first parameter equals the second parmeter, return true. Make up all the names. function compare(param1, param2) {
  if (param1 === param2) {
    return true;
  }
}
function[a-z_$][a-zA-Z0-9_$]*\(([a-z_$][a-zA-Z0-9_$]*),([a-z_$][a-zA-Z0-9_$]*)\){[\r\n]if\(\1===\2\){[\r\n]returntrue;[\r\n]}[\r\n]}
  1. I've coded a function. Leave my code intact.
  2. Call the function, passing parameters.
  3. Code an alert that displays the function's returned value.
  4. Click the Result button (or, after revising, don't click, just wait).
  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 49 in the book.
  1. I've coded a call to a function that concatenates two text fragments to create a message, followed by an alert that displays the concatenation. Leave my code intact.
  2. Code the function.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the message.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 49 in the book.