Follow-up Activity: Working with Numbers, Part II


Introduction

In this follow-up activity you will experiment with expressions that include JavaScript numbers and strings.

If your code isn't working as expected, try opening up Firefox's error console to check for (potentially) helpful error messages. If you get stuck, don't hesitate to ask the instructor or a teaching assistant for help.


Experimenting (some more) with Numbers and Strings:

  1. Copy the Working with Numbers web page to your COMP 102 workspace. Just as with the previous web page, you can do this in either of two ways:
  2. View the page source. For the most part, you should see that this activity is an extension of the Getting Started web page. The runShortExperiment function repeats the short exercises from that activity and adds several new exercises involving more complicated expressions.
  3. Review Exercises 4-7 (recommended if you don't do this follow-up activity immediately after the Getting Started activity)

    1. Exercises from Getting Started activity:
    2. (Simplified) What does the first alert statement in runShortExperiment do? (This is the only statement that is not commented-out.)
    3. Uncomment the second alert statement. (There will still be a comment to the right of the statement, at the end of the line.) What will the function will do now? Update the comment with what you expect the result to be, then test it.
    4. Now comment out both of the first two statements.
    5. In the first two statements, you displayed a string and a number. The next five statements illustrate what the the + operator does when used with numbers, strings, or a combination of both. Again, document your expected results in the comments at the end of line, then test that your expectations were correct.
  4. Building output with a mixture of strings and numbers is frequently very useful. Uncomment the first two statements that include "Expected Results" in the output. Are the Expected Results what you actually expect? Run the experiment. If any actual results are not what you expected, make sure you understand the output and then update the Expected Results. When you are done, comment out the statements.
  5. The final set of statements in this function will allow you to experiment what happens when addition and multiplication operations are combined in the same statement. Starting with just the first two statements, think about what you think the output will be, edit the Expected Results (e.g., change ??? to 42, or whatever you think the output will be), uncomment the statements, and run the experiment.

    What about the third statement in the block? Do you expect its behavior to be the same as the first statement or the second statement, or neither? Test it. Then go on and do the same for the final two statements in the function.


Publish to your web site:

  1. Make sure that you have updated the "Author:" and "With assistance from:" comments at the top of your source file.
  2. Edit the course "home page" you created in a previous activity and add a link to your new Working with Numbers, Part II page. In the link, refer to your new page with a relative pathname which is just the name of the file (e.g., <a href="NumbersPart2.html">). This tells the browser that the file to look for is in the same directory or folder as the current file (your main COMP 102 web page, in this case). You do not want to give a full or absolute pathname, like <a href="file:///Desktop/NumbersPart2.html">, because the location of your file on the student.cs.kzoo.edu server will not be the same as on your own laptop or classroom computer.

    If you worked in a team, each member of your group should do this, so each of you has a link to the new page. After the link, list your teammates in parentheses; for example, "Numbers and Strings, Part II (with Rey and Finn)".

  3. Upload both your modified COMP 102 web page and your page for this follow-up activity to the student.cs.kzoo.edu server. Test that the link to the follow-up activity works on the server by clicking on it from your home page there. (Make sure that your browser is looking at the page on student.cs.kzoo.edu, not your local version.)