Reading
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:
- Write a JavaScript program to generate the answers to a sequence of questions (deliverable)
- Use the Firebug console to view the output from your program (not deliverable).
- 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.
-
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.
-
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.
-
Assign the value "3" + 3 to the same variable, xanadu, and tell what type of information the variable holds now.
-
Assign the value "3" - 3 to xanadu, and tell what type of information the variable holds now.
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.-
Assign the value 3 - xanadu to xanadu, and tell both the new value of xanadu and its type.
-
Assign the value 3 - "xanadu" to xanadu, and tell both the new value of xanadu and its type.
Explain the difference between the previous two questions.
There is no JavaScript code to write for this question.-
Assign the value [ ] to a variable named Nan. What are the values and types of the variables, NaN, "NaN", and Nan?
Explain your answers. -
What is the type of Nan?
Hint: the answer is not what you probably expected. -
What value could you assign to Nan[0] so its type would be "number"?
-
What are the value and type of 1.23E2?
-
Assign the value function(){} to Nan[3]; tell the type of this value; tell the value of Nan.length.
-
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!