This project is intended to give students experience in composing a small web page
involving JavaScript. Although many different techniques exist for coding and executing
scripts, this project will require that the script be coded in the head section of an
XHTML file. This program will rely primarily on the use of
"[pop-up prompt (dialog) boxes]" for input and will produce
HTML output using JavaScript document.write methods.
As with prior projects, this project will be written using a plain text editor to help students
develop a fundamental understanding of XHTML and JavaScript syntax.
Request and store two numbers entered by the user via dialog boxes similar to those shown in the INPUT area of the Sample Output below. Then calculate their sum, difference, product, and quotient. Then display those results in the browser window in a manner similar to that shown in the OUTPUT area of the Sample Output below.
The INPUT area of the illustration below shows two prompt dialog boxes that your
JavaScript will have to produce in sequence to allow the user to enter two input values.
These boxes can be executed via a method named prompt. See the
W3Schools tutorial page about JavaScript Popup Boxes.
The OUTPUT area of the illustration shows how your browser window should appear when the
program is complete.

Your JavaScript code will declare its own variable labels to use to accomplish its task. The following "variable list" defines the labels you should use within your code. Notice the "camel (hump)" naming convention used on the first two variable identifiers, that uses capitalization in place of blank spaces.
| LABEL | DESCRIPTION | SOURCE | USAGE | DESTINATION |
|---|---|---|---|---|
| firstString | First digit string enter by the user | prompt dialog box | for first | Browser Document |
| secondString | Second digit string enter by the user | prompt dialog box | for second | Browser Document |
| first | First converted entry value | assigned from parsed firstString |
for sum, diff, product & quotient |
--- |
| second | Second converted entry value | assigned from parsed secondString |
for sum, diff, product & quotient |
--- |
| sum | Sum of first plus second | Calculated | --- | Browser Document |
| diff | Difference of first minus second | Calculated | --- | Browser Document |
| product | Product of first times second | Calculated | --- | Browser Document |
| quotient | Quotient of first divided by second | Calculated | --- | Browser Document |
You are not required to analyze the steps necessary to accomplish the objective of the script. That work has already been done for you, resulting an an "algorithm" (logical recipe) as follows.
A. Start.
B. Store data acquired from the two prompt dialog boxes.
B1. firstString from a prompt dialog box.
B2. secondString from a prompt dialog box.
B3. Parse firstString as a floating point number and assign it to variable first.
B4. Parse secondString as a floating point number and assign it to variable second.
C. Calculate and store results.
C1. sum as first plus second.
C2. diff as first minus second.
C3. product as first times second.
C4. quotient as first divided by second.
D. Display results in the browser's document window as seen in the Sample OUTPUT.
D1. Page Heading (H3).
D2. A paragraph element showing the two string values entered.
D2a. firstString
D2b. secondString
D3. A paragraph element showing the results.
D3a. sum.
D3b. diff.
D3c. product.
D3d. quotient.
E. Display blank line and wrap-up message as seen in the Sample OUTPUT.
F. End.
Note that steps B-D should be handled by JavaScript code in the head section of the web page, but step E should be performed as part of the body section of the web page. Read the source code for the JavaScript example file entitled "Entirely in the head section" posted on my web site at:
http://www.gibsonr.com/classes/internet/examples/javascript/jsex_all_in_head.htm
In order to execute the JavaScript content of that document, you might have to reconfigure your browser's security settings as described on the page about Browser Security Configuration for Scripts.
Web document content generated by script instructions in the head section (as shown in the example referenced above) will precede document content contained in the body section of the XHTML file.
txt to the end of the
filename.<!-- Comment here --><?xml version='1.0' encoding='utf-8'?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
// style of JavaScript comment notation at the front of those
statements to "comment out" the alert statements prior to submitting your code.
For example: //alert ("Input section of script reached.");<!-- and --> in XHTML and /* and */
in JavaScript) to mask any code that is causing trouble, move on to a different element,
and come back to solve the problem later.
Some frustration can be a valuable motivator to reinforce lessons.
But too much can inhibit learning.
Schedule your time to allow some breaks between working sessions.Login to the and use the Project 4 drop box under the Lessons tab to attach your "project4.htm" file.