HTML and CSS Reference
In-Depth Information
Exercises
1. Create an array of five animals. Use a for loop to display the values stored there.
Now add two more animals to the end of the array and sort the array. (Use Java-
Script's built-in array methods.) Display the sorted array.
2. Create an associative array called colors . Each element of the array is a string
representing the color, for example, red or blue . Use the for/in loop to view each
element of the array with a color of the font the same color as the value of the
array element being displayed.
3. Create a function that will return the current month by its full name. Use the
Date object to get the current month. Months are returned as 0 for January, 1 for
February, 2 for March, and so on. Output should resemble this:
The current month is January.
Hint: You can create an array, starting at index 0, and assign a month value to it;
for example, month[0]=“January” or use a switch statement, for example, case 0:
return “January” .
4. An invoice is due and payable in 90 days. Write a function that will display that
date.
5. How many days until your birthday? Write a function to calculate it.
6. To calculate the balance on a loan, the following formula is used:
PV = PMT * ( 1 - (1 + IR ) -NP ) / IR
PV is the present value of the loan; PMT is the regular monthly payment of the
loan; IR is the loan's interest rate; NP is the number of payments remaining.
Write a JavaScript statement to represent this formula.
7. Using the formula to calculate the loan balance from the last exercise, write a
function that will calculate the principal balance left on a loan where the monthly
payments are \$600, the annual interest rate is 5.5 percent, and there are 9 years
remaining on the loan. Use the toFixed() Number method to format the output.
8. Apply the ceil() , floor() , and round() methods to the number 125.5567 and dis-
play the results.
9. Create an array of 10 fortune cookies that will be randomly displayed each time
the user reloads the page. The fortune will be a saying like: “Procrastination is
the thief of time.”
Search WWH ::

Custom Search