1 2

advertisement
SI110 Homework Alpha: ________ Name: ____________________
Page 1 of 2
Collaboration Policy: Default
MIDN Last, F.
choose one: □ None □ XS110 □ EI with:
(or more)
□ MGSP
□ Discussed with: ____________________________
Homework: /SI110/Cyber Battlefield/Programs – Statements & I/O
For this assignment you are expected to use:
http://rona.academy.usna.edu/~si110/resources/interpreter.html
the line-at-a-time JavaScript interpreter,
http://rona.academy.usna.edu/~si110/resources/batchInterpreter.html
the batch JavaScript interpreter,
or the JavaScript console included with your browser.
1. [20 / 15 / 10 / 0] Write a JavaScript statement that produces
the depicted alert box. Note: Use the line-at-a-time interpreter
(URL above) to experiment and make sure your solution
works!
2. [ 20 / 15 / 10 / 0 ] Copy and paste the following program into
the batch interpreter and run it. Then modify it so that the state
tax rate is entered by the user rather than set to 0.06 in the code
(this is referred to as being “hard coded”). The user should enter a
rate as a percentage, so for a rate of 6.25% the user would enter
6.25 (as shown to the right) not 0.0625.
Annotate the code below to show how you modified it!
var base = 87.50;
var hbo = 4.99;
var stateTaxRate = 0.06;
var federalFee = 0.71;
var monthly = base + hbo;
var total = monthly + monthly * stateTaxRate + federalFee;
alert(total);
SI110 Homework
Collaboration Policy: Default
Page
2 of 2
3. [ 30/ 25/ 15/ 0 ] Copy and paste the following program into the batch interpreter and run it.
Modify the program so that the user can enter their own 4 letter word which is converted to
binary for them.
Hint: .toString(2) changes the value in front of it to binary, don’t change that part.
Annotate the code below to show how you modified it!
var b ="";
b = b + 'N'.charCodeAt(0 ).toString(2);
b = b + 'a'.charCodeAt(0 ).toString(2);
b = b + 'v'.charCodeAt(0 ).toString(2);
b = b + 'y'.charCodeAt(0 ).toString(2);
alert("Navy in binary is: "+ b);
4. Complete the following after exploring the below URL:
http://rona.academy.usna.edu/~si110/lec/prgmIO/hw/classOf.html
Hint: Use the source, MIDN.
Note: Complete the below by only changing the data you input into the program, DO NOT alter
the source code.
a. [ 5 / 3 / 0 ] What number did you want as part of the end result (your goal)?
b. [ 10 / 8 / 5 / 0 ] What was your input to the first prompt to achieve your goal?
c. [ 15 / 10 / 7 / 0 ] What was your input to the second prompt to achieve your goal?
Download