CHS Web Design Track

JavaScript for Web Warriors, 7e Chapter 2: Working with Functions, Data Types, and Operators

Chapter Reinforcement

MULTIPLE CHOICE

  1. How would you express the number 0.0055 in exponential notation?
    1. 5.5e-3
    2. 5.5e3
    3. 55 ◊ 103
    4. 0.0055
  2. When HTML and JavaScript code are written in separate files, the command document.getElementById(“happy”).onclick = makeIceCream; is used to _____.
    1. create an on-click event handler as an attribute of the happy object in an HTML file
    2. place an on-click event handler for the happy object within JavaScript code
    3. call the makeIceCream() function with happy as an argument
    4. add an event listener for the happy object within JavaScript code
  3. What programming structure that can be called repeatedly throughout a program consists of a collection of statements that share a common purpose or calculate a value?
    1. parameter
    2. function
    3. command block
    4. object
  4. Which JavaScript expression can you use to retrieve the value from the web form input control with the id “numberOfParticipants”?
    1. getInputValue(“numberOfParticipants”)
    2. let value = document.getElementById(“numberOfParticipants”)
    3. document.getElementById(“numberOfParticipants”).input
    4. document.getElementById(“numberOfParticipants”).value
  5. After the following JavaScript code executes, the value of c will be _____.
    let a = 8;
    let b = ++a;
    let c = b--;
    1. 8
    2. 10
    3. 7
    4. 9
  6. The JavaScript expression discount == 10 _____.
    1. returns true if the number 10 is stored in the variable discount
    2. returns false if the number 10 is stored in the variable discount
    3. assigns the value 10 to the variable discount
    4. will result in an error because you cannot use variable names as operands with comparison operators
  7. What does the JavaScript expression document.getElementById(“numberOfParticipants”).value = 0; do?
    1. returns a Boolean true if the value of the input control with the id “numberOfParticipants” is 0
    2. retrieves the value entered by the user for the input control with the id “numberOfParticipants
    3. sets the value of the input control with the id “numberOfParticipants” to 0
    4. results in an error because of incorrect syntax
  8. Which of the following would NOT be represented as a floating point number in JavaScript?
    1. 4.77 ◊ 106
    2. 3.5
    3. -12
    4. 89
  9. In JavaScript, if the variable flower has been assigned the value “bluebell”, the expression typeof(flower); will return _____.
    1. variable
    2. string
    3. bluebell
    4. void
  10. What change should be made to the JavaScript statement document.write(“<p>Who likes the song “Twinkle, Twinkle, Little Star”?</p>”); if the intention is to display the string: Who likes the song “Twinkle, Twinkle, Little Star”?
    1. No changes are necessary.
    2. Remove </p> from the statement.
    3. Change the third and fourth double quotation marks into single quotation marks.
    4. Insert a backslash (∖) before each of the double quotation marks around the song's title.

TRUE FALSE

  1. Most browsers display error messages they generate in a console that can be opened by website developers, and developers can use this console as a helpful debugging tool.
  2. The expression a *= b assigns b the value equal to a * b.
  3. You can use Boolean values to allow your program to decide which code blocks to execute.
  4. The only way to run a JavaScript function upon an event such as a page loading or a user clicking a page element is to enclose the function within an event handler or event listener.
  5. When the JavaScript expression (10 + 10) + 2 * 5 is evaluated, the addition within the parentheses is performed first, then the multiplication operation, then the remaining addition operation.
  6. The JavaScript expression 36-- returns the value 34.
  7. When the Google Chrome browser console reports the location of an error as js40.js:30, this means it is found on line 40 of the JavaScript file that prompted the error.
  8. The following JavaScript expression retrieves the Boolean value false when the user has selected (ticked) the box indicating he wants extra cheese, which has the id “extraCheese,” on a web form for ordering pizza.document.getElementById(“extraCheese”).checked;
  9. The use of global variables is strongly discouraged for applications managed by a team of programmers because, in comparison, the scope of local variables is well-contained and therefore more easily tracked.
  10. After the following JavaScript code executes, the message “Get back to work!” will display.
    let holiday = 0
    (holiday) ? window.alert(“Enjoy your day off!”) :
                window.alert(“Get back to work!”);