"); } else { $mime_type = "text/html"; header("Content-type: $mime_type; charset=utf-8"); } ?> CS-90.3 Assignment 2

CS-90.3 Assignment 2

Reading

We are still working on material from Chapters 1 and 2 of the Simply JavaScript book, but have also started on the material in Chapter 3. We haven’t covered Objects, the last topic in Chapter 2 yet in class, but will be doing so next. We also haven’t covered conditions (if statements) and loops (for/while statements) yet; learn as much as you can about them from the text, because we will not spend a lot of class time on them despite their being critical parts of JavaScript.

The Assignment

Introduction

This is an exercise in working with various elements of the JavaScript language: literal values, variables, expressions, functions, and arrays. The emphasis of this assignment is on identifying types of information.

There are three parts to the assignment, just two of which are “deliverables” to be submitted for grading:

  1. Write a JavaScript program to generate the answers to a sequence of questions (deliverable)
  2. Use the Firebug console to view the output from your program (not deliverable).
  3. Write out the answers to the questions for which your program generated the answers (deliverable).

Changes To Your Web Site

The only change to make to your index.xhtml file from Assignment 1 is to change the link to assignment_01.js into a link to another file named assignment_02.js.

Create the file assignment_02.js in your scripts directory, and add a sequence of statements to it that will generate the answers to the following list of questions.

Be sure the outputs from the program include the question numbers, as shown in the sample answers to the first two questions.

The Questions

I have provided you with the answer to the first two questions to provide models for doing the assignment.

  1. What type of information is 3?

    The code you write might look like this:

    console.log("1. 3 is a " + typeof 3 + ".");

    The program output should be 1. 3 is a number.—which would be the answer you type into your email for the first question.

  2. Assign the value "3" to a variable named xanadu, and tell what type of information the variable holds.

    var xanadu = "3"; console.log("2. xanadu is a " + typeof xanadu + ".");

    The program output should be “2. xanadu is a string.”—which would be the answer you type for the second question.

  3. Assign the value "3" + 3 to the same variable, xanadu, and tell what type of information the variable holds now.

  4. Assign the value "3" - 3 to xanadu, and tell what type of information the variable holds now.

  5. Explain the difference between the effects of the + and - operators in the previous two questions.

    There is no JavaScript code to write for this question.
  6. Assign the value 3 - xanadu to xanadu, and tell both the new value of xanadu and its type.

  7. Assign the value 3 - "xanadu" to xanadu, and tell both the new value of xanadu and its type.

  8. Explain the difference between the previous two questions.

    There is no JavaScript code to write for this question.
  9. Assign the value [ ] to a variable named Nan. What are the values and types of the variables, NaN, "NaN", and Nan?

    Explain your answers.
  10. What is the type of Nan?

    Hint: the answer is not what you probably expected.
  11. What value could you assign to Nan[0] so its type would be "number"?

  12. What are the value and type of 1.23E2?

  13. Assign the value function(){} to Nan[3]; tell the type of this value; tell the value of Nan.length.

  14. What is the type of the value, { }?

Submit

When you have tested your code and determined the answers to the questions, type your answers into the body (not an attachment) of an email message, and send it to me. I’ll copy your entire web site to my computer (babbage) and check out your code and will check your email to be sure you answered the questions correctly.

Send your email message to me at: vickeryatbabbage.cs.qc.cuny.edu by midnight of the due date.

The Subject line of your email message must be: “CS-90.3 Assignment 2.”

Don’t forget to put your name in your email message!