Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

Answers CHAPTER 3 135


C. Incorrect: Microsoft Test does not support JavaScript.
D. Incorrect: NUnit does not support JavaScript.


  1. Correct answer: B
    A. Incorrect: You need to write a failing test first so you can see the test pass after
    you write the code.
    B. Correct: You write a failing test and then write code that makes the test pass; then
    run the test again to validate that it passes.
    C. Incorrect: You should never write code without first writing a test that fails.
    D. Incorrect: If you write a passing test first, the code cannot be tested for success.

  2. Correct answer: C
    A. Incorrect: Placing your JavaScript code in the element does not promote
    reuse, and inline code might reference elements that are not yet loaded.
    B. Incorrect: Placing your JavaScript code in the tag does not promote
    reuse.
    C. Correct: Placing your JavaScript code in separate files, external to your HTML
    document, promotes reuse.
    D. Incorrect: Placing your JavaScript code in the element does not promote
    reuse, and inline code might reference elements that are not yet loaded.


Lesson 3



  1. Correct answer: A
    A. Correct: Concat concatenates multiple arrays and produces a resultant array.
    B. Incorrect: Join creates a string from the items in the array.
    C. Incorrect: Push adds a single item to the end of the array.
    D. Incorrect: Splice adds and removes items from an array and produces a resultant
    array, but you must add the items one by one, not as an array.

  2. Correct answer: C
    A. Incorrect: getElementsByName retrieves a live NodeList of elements based on the
    element’s name attribute, not on the tag name.
    B. Incorrect: querySelectorAll is capable of retrieving the elements by tag name, but
    returns a static NodeList, which does not perform as well as functions that return a
    live NodeList.
    C. Correct: getElementsByTagName retrieves a live NodeList of elements based on
    the element’s tag name.
    D. Incorrect: getElementsByClass retrieves a live NodeList of elements based on the
    CSS class name.

Free download pdf