Questions for JavaScript Lesson 1

  1. Which of the following is/are legal variable names?
    this is a legal name Yes it's legal No it isn't!
    is_this_legal? Yes it's legal No it isn't!
    temp164 Yes it's legal No it isn't!
    MYAGE Yes it's legal No it isn't!
    67temp Yes it's legal No it isn't!
    TeMpOrArY_VaLu_E Yes it's legal No it isn't!
  2. What is displayed by each of the following statements? Type your answers in the slots provided.

    <script language="JavaScript">
    var value1 = 36, value2 = 15;
    document.write("value1 + value2");
    document.write("value1" + value2);
    document.write(value1 + "value2");
    document.write(value1 + value2);
    </script>

  3. Rewrite the following using just one instruction:

    document.write("The answer to the calculation is ");
    document.write(answer);
    document.write(".");
    document.write("<p />");
    

    (Hint, you can incorporate <p /> as part of other strings, or concatenate it to other strings.)

  4. Write a full JavaScript program that displays the answers to the following calculations in white text on a blue background: 141 x 302, 15772 + 3205 and 6000 / 47118.

  5. What's wrong with the following program? There are several errors. Correct the program so that it works properly. What is the number displayed on the screen?

    <language script="JavaScript"
    document.bgcolour = "black";
    write(<font color=yellow>);
    first number = 200
    2nd_number = -136;
    answer = first number * 2n d_number + 400
    document write("The answer is " answer.)
    <script>
    

  6. The following text shows the HTML needed to display a table with three columns. How would you rewrite this so that the table was displayed using JavaScript only?

    <table>
    <tr>
        <td>This is the first column</td>
        <td>Now the second</td>
        <td>And this is the third</td>
    </tr>
    </table>