Reading
- JavaScript Text, Chapter 6 (Using Object-Oriented JavaScript Date Class, Number Class, and Math Class), pgs 285 - 305
- Page 291, last line in step 4, should be method of the "dateObject". The book says "dataObject".
Page 298, Line 9: The text example does not close the "input" with a space
slash. Also, there is a logic error on the same page in the
calcGroupDiscount(). Neither groupSize = 5 or groupSize
= 10 is included in the text. Both result in no discount being applied.
Additionally, if toLocaleString() results in comma-delimited American-style numbers.
However, IE displays it with decimals. ex) $1,357.00
Firefox displays no decimals. ex) $1,357. (This is what the textbook displays.
-
// ********************************************************
// the code specified for getting days of month on pg 293
// is flawed. It does not take into account whether the year
// is leap year which changes the number of days in Feb
// daysInMonth function takes care of days in leap and nonleap years
// this snippet came from http://snippets.dzone.com/posts/show/2099
function daysInMonth(iMonth, iYear)
{
return 32 - new Date(iYear, iMonth, 32).getDate();
}
// now that's an amazing function!
//**********************************************************
Vista Problems
Students reported to me that they kept having errors. I couldn't see the errors. Then I was sent this message.
After testing the code version that you sent and finding that it produced the same error that I was getting,
I did more research on the web and apparently the challenge has to do with Windows vista and the "Computer"
zone security vs internet security and "protected mode". One site said I should turn protected mode on for my
local zone, while another site cautioned about what a bad idea that is.
When I uploaded my version to the linux, it works fine from there.
Therefore, if you keep getting unexplained errors and you are using Vista, please upload to the class server and see if the
error still exists.
We never upgraded to Vista at ACC because we always found too many problems with it. I have bought only one computer since Vista has been out.
I had so many problems, that after a month, I removed Vista and installed XP. So, I do not have experience with Vista. I never plan to have
any experience with Vista. I have heard that Windows 7 is a good product.
Discussion
- Using the Date Class
- To use the Date class you need to define objects of that type. Defining the object is similar to defining an array.
- Used to work with dates and times.
- Automatically holds the current date and time as its initial value.
- Example of instantiating the Date Object (which will default to the current date):
- var currentDate=new Date();
- Example of overriding the default value with June 15, 2009 (see page 286 for commonly used methods):
- var anotherDate=new Date();
anotherDate.setDate(15);
anotherDate.setMonth(5); // January = 0
anotherDate.setFullYear(2009);
- Example of comparing currentDate to anotherDate:
- if (currentDate < anotherDate)
window.alert("The current date is before June 15, 2009");
else
window.alert("The current date is either June 15, 2009 or after June 15, 2009");
- Example of changing the date to yesterday:
- anotherDate.setDate(anotherDate.getDate()-1);
- If subtracting one day from the date causes the date to be in the preceding month and/or year, the changes to the month and year
portions of the date are handled automatically by the date class itself.
Practice
- Using the Date Class
- CVSGroups.html Page
- Open your template.htm page in your editor.
- Save your template as CVSGroups1.htm in your assignment2 folder. (Notice the addition of the number 1 in the
name of the file and no l in the extension htm. You can set your default choice in the LTS editor.
When I provide a file provided with the text, it will have the extension html.)
- I have entered much of the code in hopes that you will spend your time studying the code rather than keying it all in and
searching for typos. Please notify me if you find typos in my pages so that I can make corrections.
- Since you already saved your template, you have already completed steps 1 and 2 on page 288-289 except you
still need to change the title.
- I have provided the coding for:
page 289 step 3
page 289 step 4
- (remember to insert this before the close form tag in step 3)
- I also added the code from page 291, step 2 to this code. The link won't work yet.
page 289 step 5(remember to insert this before the submit button in step 4)
page 290 step 6(remember to insert this in the script section between
the /* <![CDATA[ */ and /* ]]> */)
/* <![CDATA[ */
(put code here)
/* ]]> */
- Save in the assignment2 folder. Since I added the line of code from page 291, your page may not validate.
However, you should still try to get out any validation errors that you can.
View your page by clicking the preview tab on the right.
JavaScript typos will show up in LTS when viewed this way.
Check to see that your page looks like Figure 6-6 on page 290.
- You can test the page with any form processing page that you wish to reuse.
- I have provided the coding for:
function displayCalendar()
pages 291-295 (remember to insert this above
/* ]]> */
- Check to see that your page validates and that it looks like Figures 6-7 on page 294 and Figure 6-8
on page 296.
Discussion
- Number Class
- Used to define, manipulate, and modify numeric values
- Defines methods such as toFixed(), toPrecision(), toString(), valueOf(), toExponential(), Number(), toLocaleString()
- Defines special values such as MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY
Practice
- Accessing Number Class Properties
- CVSGroups2.htm Page
- If necessary, open CVSGroups1.htm from your assignment2 folder in your editor.
- Add the coding from pages 297 - 298 of your JavaScript text. Note, the 10% discount is
written incorrectly. My book shows dailyRate = 49/1.1; It should be
dailyRate = 49 * .9;
- Save the document as CVSGroups2.htm.
- Compare your page to figure 6-9, page 299.
Discussion
- Math Class Methods
- Contains methods and properties for performing mathematical calculations.
- There are eight mathematical constants accessible from the Math object. For Example:
E, PI, square root of 2, square root of 1/2, natural log of 2, natural log of 10,
base-2 log of E, and base-10 log of E.
Practice
- Using Math Class Methods
- CVSGroups3.htm Page
- If necessary, open CVSGroups2.htm from your assignment2 folder in your editor.
- Add the coding from page 301 of your JavaScript text.
- Save the document as CVSGroups3.htm.
- Compare your page to figure 6-10, page 302.
- Declaring Basic Custom Objects
- CVSGroups4.htm Page
- If necessary, open CVSGroups3.htm from your assignment2 folder in your editor.
- Add the coding from #1 on page 304 of your JavaScript text.
- Save the document as CVSGroups4.htm.
- Compare your page to figure 6-12, page 305.
Project for this assignment
- Create currency.htm
- Open your template.htm page.
- Save your page as currency.htm.
- Your currency page should:
- Display the current date and tomorrow's date.
- Contain a form with:
text that asks "What is the amount of U. s. dollars you want to convert?"
a textbox to allow the user to enter an amount.
text that asks "To which currency would you like to convert?"
Radio buttons for 3 different currencies. For example:
British Pound
EUR
Peso
A button with the value Convert

- Link to a css page that you are to create.
- Save your document in your assignment2 folder.
- Create a css page to create an attractive, readable page.
- Create conversion.htm
- Using the choice sent by the user, convert the amount entered to the foreign rate.
- To determine which conversion you are to make, (remember you gave 3 choices) use the switch statement.
- Using the values of the USD entered and the conversion currency, convert the value.
- Currency Converter for 164 Currencies
- To use this site
- Enter a 1 in the text box labeled Convert amount
- Enter USD in the first text box labeled Currency Code
- Enter the appropriate abbreviation in the second text box labeled Currency Code
- Click the button Convert Now
- You will be given the equivalent amount of 1 US dollar.
- Use that amount to multiply times the amount entered by the user to get the conversion amount.
- Display the results. The gif example below shows how a page might look.
The first line says: "Thank you for using Express Conversion"
There is a blank line.
The second line says: 100 U S Dollars = 77.40178 Euro
Then, show the validation icons for both XHTML and CSS taken from the template.
The conversion rate you use may have changed, and you may make your output as you wish as long as it
can be read. Here is the gif just described.

Update your index page:
- Add links on your index page to the pages in your assignment2 folder that are to be graded:
- CVSGroups4.htm
- any form processor that you wish to reuse
- currency.htm
- conversion.htm
- css page used
Uploading:
- Upload your revised index.htm page to the public_html folder.
- Upload your assignment2 folder with the files:
- CVSGroups4.htm
- any form processor that you wish to reuse
- currency.htm
- conversion.htm
- css page used (this page may be in a different folder, just link correctly in
your pages and on your index page)
Testing uploaded pages
- Once uploaded, go to your site http://cois-linux.austincc.edu/~login/
- Validate your index page and all pages in this assignment (your css page will validate through the
html pages that refer to your css page)
- Make any corrections for any page that does not validate or display correctly.
- Email me for grading.