JavaScript
Exercise 1
Advanced Web Development
152-121
JavaScript Syntax
Exercise
Exercise goals:
- Learn how to write simple JavaScript code
- Learn JavaScript syntax
- Understand the language elements of JavaScript
You may work with the person sitting next to you if you like. Sa ve this file
and insert the code for the following situations
- Write the code to create an array that will store 4 items. Then populate
the array with the following values:
First item="Apple"
Second item="Orange"
Third item="Kiwi"
Fourth item="Pomegranate"
- Using the following variables, write a statement to arithmetically add the
two values. If you wish to work online, display the results in an alert
box.
var subtotal=1000.00
var tax="5.50"
- Using the following variables, write a statement to concatenate the two
values. If you wish to work online, display the results in an alert
box.
var subtotal=1000.00
var taxRate=.055
- Write a statement to calculate the total tax by multiplying the subtotal
by the taxRate. Store the result in subtotal.
var subtotal=1000.00
var taxRate=.055
- Write a statement to determine if the input field (stored in a variable
called inputValue) contains a space (" ")
or a null value(null).
Display the results in an alert box.
- Write a statement to check to see if the country (stored in a variable called
country) is not
equal to either "United States" or "USA";
Display the results in an alert box.
- Write a statement to determine if a variable called age
is greater than or equal to 18 and less than 30.
- Write the code to call a function named checkAmount, passing it two parameters:
amountValue and fieldName. Include the actual function statement and curly
brackets in your code.
- Write the code to loop 10 times. Each time through the loop multiply a counter
(starting with 1) by itself and adding the total to a variable called sum.
After the loop, write the results into the document.
- Write the code to do the following events and actions You do not have to
write the actual code, just include the statements below:
- When the document has loaded, call a function called initialize.
Add this to the body tag of this page.
- When a input text box value has changed run a function called calculateAmount.
- When the cursor moves over an input text box (shown above) change the
browser status line to the text 'Please enter the amount'.