1 2

advertisement
SI110 Homework
Alpha: ________ Name: ____________________ Page 1 of 2
Collaboration Policy: Default
choose one: □ None □ XS110 □ EI with:
(or more)
□ MGSP
□ Discussed with: ____________________________
Homework: /SI110/Cyber Battlefield/programs – Expressions & Variables
For this assignment you are expected to use:
http://rona.academy.usna.edu/~si110/resources/interpreter.html
the line-at-a-time JavaScript interpreter, or the JavaScript console included with your browser.
1. [ 10 / 8 / 5 / 0 ] Consider the following two code snippets:
// Snippet A
var x = 3;
var y = "3";
var z = x + y + x;
// Snippet B
var x = 3;
var y = "3";
var z = x + Number(y) + x;
Is the value of z in Snippet A the same as the value of z in Snippet B? Why or why not?
2. [25 / 20 / 15 / 10 / 5 / 0] The typeof( ) function returns a string that corresponds to the
type of the function’s argument (i.e. what was in parentheses). For the following questions, you
are expected to actually use a JavaScript interpreter (see above!) to evaluate statements.
a. What is the value of: typeof("true"); ? Why?
Value:
Explanation:
b. What is the value of: typeof(true); ? Why isn't it the same as 3.a.?
Value:
Explanation:
c. What is the value of: typeof(12.5); ? Why?
Value:
Explanation:
d. What is the value of: typeof('12.5'); ? Why isn't it the same as 3.c.?
Value:
Explanation:
e. What is the value of: typeof(typeof(3)); ? Why?
Value:
Explanation:
SI110 Homework
Collaboration Policy: Default
Page
2 of 2
3. [ 10 / 8 / 5 / 0 ] For the following questions, you are expected to actually use a JavaScript
interpreter to evaluate statements.
a. What is the value of: 'can't do this' ? Why?
Value:
Explanation:
b. Write a JavaScript string literal that evaluates to the string can't do this .
4. [ 20 / 15 / 10 / 5 / 0 ] Consider the following sequence of JavaScript statements entered and
evaluated consecutively:
var Val = ‘Navy’;
What is the value of Val after evaluation?
t = Val.charCodeAt(2);
What is the value of t after evaluation?
t = ‘Navy’.charCodeAt(3);
What is the value of t after evaluation?
t = String.fromCharCode(110);
What is the value of t after evaluation?
5. [ 15 / 10 / 5 / 0 ] Complete the following.
a. Write a JavaScript assignment statement that assigns the value I "know" I can to the
variable y, without using single quotes (').
b. Write a JavaScript assignment statement that assigns the value this isn't that bad to the
variable x, without using double quotes (").
c. Write a JavaScript assignment statement that assigns the value I've got "skills" to the
variable z.
6. [ 20 / 15 / 10 / 5 / 0 ] Consider the following sequence of JavaScript statements entered and
evaluated consecutively:
var t = 5;
What is the value of t after evaluation?
var a = 5;
What is the value of t after evaluation?
t = t + a;
What is the value of t after evaluation?
t = t * t - a;
What is the value of t after evaluation?
Related documents
Download