PATH: Instructional Server> GRA 3758> Projects>

GRA 3758 Project 4 - Simple Embedded JavaScript


Project Purpose:

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.

Program (Script) Objective:

The script shall request and store a person's height in meters (which could be entered as a floating point number). Then, convert that value height into whole feet and inches rounded to the nearest inch. Finally, display those results in the browser window in a manner similar to that shown in the OUTPUT area of the Sample Output below.

Sample Output:

The illustration below shows a prompt dialog box that your JavaScript will have to produce to allow the user to enter an input value. This box can be executed via a method named prompt. The default value of 0.0 must be specified in the JavaScript command. It will not happen automatically.

Project 4 Prompt Illustration

See the W3Schools tutorial page about JavaScript Popup Boxes. The illustration shows how your browser window should appear when the program is complete if the user had entered the input "1.8"" into the prompt dialog box.

Project 4 Illustration

Variable List:

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 variable identifier, that uses capitalization in place of blank spaces.

LABEL DESCRIPTION DATA TYPE SOURCE USAGE DESTINATION
hmString Entered height in meters String Prompt dialog box For hm Browser Document
hm Parsed height in meters Floating point Assigned from
parsed hmString
For totinches ---
totinches Total height in whole inches Integer Calculated For feet and inches ---
feet Whole feet portion of height Integer Calculated --- Browser Document
inches Whole inches portion of height Integer Calculated --- Browser Document

Algorithm:

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 in an "algorithm" (logical recipe) as follows.

A. Start.
B. Request and store data acquired from a prompt dialog box.
   B1. hmString from a prompt dialog box.
   B2. Parse hmString as a floating point number and assign it to variable hm.
C. Calculate and store results.
   C1. Assign totinches as the rounded result of: hm times 100 (cm/m) divided by 2.54 (cm/inch).
   C2. Assign feet as the integer portion of: totinches divided by 12.
   C3. Assign inches as the remainder of: totinches divided by 12.
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 input string hmString.
   D3. A paragraph element showing the results.
       D3a. feet.
       D3b. inches.
E. Display paragraph element containing a 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.

Project Constraints and Objectives:

Tips:

Submission:

Login to the and use the Project 4 drop box under the Lessons tab to attach your "project4.htm" file.

PATH: Instructional Server> GRA 3758> Projects>