I've put some good links to JavaScript programming on the References page
Lab Assignment - All JavaScript assignments go into the "H:/JavaScript" folder
Create a "Hello World" web page using HTML
and JavaScript. Refer to the w3schools page for help. Call the web
page "helloWorld.htm" and save it in the "H:/JavaScript" folder.
Test the page; make it work before continuing
Modify the "helloWorld.htm" web page. Use JavaScript to control the text formatting:
Ms. Russen will visit and discuss how to read the classified help-wanted advertisements in the newspaper.
What percentage of job openings are listed in the paper?
Copy your "salary1.htm" web page to "salary2.htm" and modify it to let
the user enter the number of hours worked and also calculate overtime pay. Overtime is calculated
at 1.5 normal pay for any hours over 40. There are two ways to calculate overtime. Both result in the same answer.
Choose one:
Create a new folder called "H:/JavaScript/Grades" for a new webpage called "grades1.htm". This page will prompt the user for a number input between 0 and 100 and calculate a letter grade for students in Adam's School according to the following grading chart:
Test for many possibilities: (105, 100, 99, 95, 90, 89, 85, 75, 65, 55, 0, -5)
Copy "cashRegister2.htm" to "cashRegister3.htm". Modify to add a loop that allows the user to enter
purchase price of items:
Declare a new variable "var anyMore = 'Y'"
Start a loop "while(anyMore == 'Y') {"
Keep a running total of items purchased.
Prompt the user "anyMore = prompt('Do you have any more purchases? (Y/N)','y');"
The loop will end when the user enters something other than 'Y'
End the loop when the user says there are no more items to be purchased.
The rest of the page is the same: display total amount purchased, prompt for amount tendered, display
change due, and calculate proper change (20's, 10's, etc.)
JavaScript Functions - a function
is defined by webopedia.com as "a named section of a program that performs a specific task". You can reduce
the amount of lines in your code (and the size of your file) by using functions. A function has the following
characteristics:
Web sites with good tutorials about JavaScript functions:
Create a new "cashRegister4.htm" web page that will use input, calculations, decisions, loops, and functions
to simulate a real cash register:
One of the rules for using global variables inside functions is to declare all
your variables before your functions. Think about the older cash registers and declare variables for
purchasePrice, totalPurchase, amountTendered, and change. Also declare a sentinel variable to control
a loop whether there are more purchases
Declare a function to get purchases using global variables:
Prompt the user for the purchasePrice
Check that it is a number
Display the purchasePrice on the browser
Display the totalPrice on the browser
Add it to the totalPurchase
Create a loop and inside
Call the function
Ask the user if there are more purchases
Test it to make it work
Display the final totalPurchase on the browser
Prompt the user for an amountTendered
Display the amountTendered on the browser
Calculate the change
Display the change on the browser
Test it to make it work
Declare a function to calculate change:
Receive arguments [inside the parenthesis] for size and currency
size is the size of the change amount [20, 10, 5, 1, 0.25, 0.10, 0.05, and 0.01]
currency is the words part ["twentys","tens","fives","ones","quarters","dimes","nickels","pennies"]
Calculate the number of size of currency [var nsc = Math.floor(change/size)]
Display number of size of currency and the words on the browser [document.write(nsc + currency + "<br>"]
Use modulus and size to modify the change variable
Call the calculate change function passing arguments 20 and "twenty"
Test it to make it work
Call the calculate change function for the rest of the currency size amounts
The concept of Random Numbers - a truly random number is one that cannot be predicted with any
accuracy. In a series of random numbers, the series has no predictable pattern, the numbers are independent, with
no correlation between successive numbers. Some websites about randon numbers:
Four steps to generate pseudo-random numbers in JavaScript:
Math.random() returns a number between 0 and 1
Multiply by one greater than the range of numbers, if 0 to 5, multiply by 6
Add to reach the starting number, for 1 to 6, add 1
Math.floor() removes the decimal points
Examples:
ranNum = Math.floor(Math.random()); // returns a 0
ranNum = Math.floor(Math.random() * 2); // returns a number between 0 and 1
ranNum = Math.floor(Math.random() * 10); // returns a number between 0 and 9
ranNum = Math.floor(Math.random() * 10 + 1); // returns a number between 1 and 10
ranNum = Math.floor(Math.random() * 6 + 1); // returns a number between 1 and 6
ranNum = Math.floor(Math.random() * 100); // returns a number between 0 and 99
ranNum = Math.floor(Math.random() * 100 + 1); // returns a number between 1 and 100
ranNum = Math.floor(Math.random() * 50 + 25); // returns a number between 25 and 75
On-screen practice with JavaScript pseudo-random numbers:
Create a web page called "randomDemo.htm" using JavaScript to generate and display a pseudo-random number
Modify "random.htm" to generate and display 100 pseudo-random numbers between 0 and 9
Add onto "random.htm" to simulate flipping a coin 1000 times, count how many times you get heads vs. tails, display your results
Add onto "random.htm" to simulate rolling two dice, display a list of 5 pairs of numbers between 1 and 6
On-screen practice with JavaScript and Forms:
Create a web page called "formDemo.htm" using JavaScript and forms
Add a form button object, onClick call a function to display an alert box message "You Clicked On Me"
Add a text box object for First Name, add a button object, onClick call a function to display the name in an alert box, change the name to "HaHaHa"
Modify the text box button to validate user input field not empty and set the focus if empty
Add two radio button objects for Male or Female, add a button object, onClick call a function to display the checked radio button in an alert box
Validate that one radio button is checked
Add a select option object for Grade Requested (A, B, C, or Other), add a button object, onClick call a function to display the selected option in an alert box
Validate that one option is selected
Add seven checkboxes for Favorite Pets, add a button object, onClick call a function to display the checked pets in an alert box
No validation, the user may choose to check none of the checkboxes
Lab - "coinToss.htm" - Create a new web page and write the HTML and JavaScript code to simulate tossing a coin and display the results in textboxes:
Add a form, give it a unique name
Add two textboxes for heads and tails, give them each a unique name
Add a button for "Flip Coin"
When the user clicks on "Flip Coin", run a function to simulate flipping a coin 1000 times, count heads and tails, and display the heads and tails results in the textboxes
Test
Make it look good
Lab - "dice.htm" - Create a new web page and write the HTML and JavaScript code to simulate rolling a pair of dice and display the results in textboxes:
Add 18 textboxes in three columns, Die 1, Die2, and Total, give them each a unique name. This would be a good place to copy and paste and change a name
Add a button for "Roll Dice"
When the user clicks on "Roll Dice", run a function to simulate rolling two dice 6 times, and display the results in the 12 die1 and die2 textboxes
Display a total for each pair of dice in the corresponding total textbox
Test
Make it look good
Lab - "guessMyNumber.htm" - Create a new web page and write the HTML and JavaScript code to simulate a number guessing game and display the results in textboxes:
Give it a try
Break the problem into small steps
Continue making smaller steps until you can't break any steps any further
Write the HTML and JavaScript code for each step
Be sure to provide the user with plenty of feedback and information
On-screen practice with some of the JavaScript Tricks listed above
Work on the labs from yesterday
Start thinking about next week's Holiday project, a multi-page website with loads of information and pictures
about the coming holiday season. On Monday you will complete and submit a project proposal along the lines of
Wilson Internet Website Planning Worksheet
.
Purpose, Organization, Graphics, Colors, Navigation, Page Elements, and (Photos, Graphics, Animations, Sound, and Video)
On-screen practice with some of the JavaScript Tricks listed above
Work on the labs from Wednesday
Continue thinking about next week's Holiday project, a multi-page website with loads of information and pictures
about the coming holiday season. On Monday you will complete and submit a project proposal along the lines of
Wilson Internet Website Planning Worksheet
.
Purpose, Organization, Graphics, Colors, Navigation, Page Elements, and (Photos, Graphics, Animations, Sound, and Video)
Complete on-line then print and hand-in my Web
Site Planning Form. I will grade and return them.
Begin design of a Holiday WebSite worth 50pts to be completed by and reviewed in class on Friday.
Define the objective of your site by completing the web site planning form listed above. Defining your goals will help shape the design and functionality
Make a list of features you want on the site - make your site distinctive and unique
Think about content - what you want to communicate to visitors
Create a folder called "css##-holiday" on "H:/" and put all your work and images there
Assemble site content - gather together any text, graphics, or other materials you want and put everything in the same folder
Research the competition - perform searches for similar websites
Make it look good. Use images and content from other internet websites
use some JavaScript techniques
Test (preview) your web page frequently
Save your file frequently
You have four days to finish this assignment. Do your best, take your time, but DON'T DAWDLE
On Friday we will evaluate each other's websites
Check your grades and complete any incomplete labs, quizzes, worksheets
Think of some simple games that you want to try and design for web pages next week (you have to give me a couple
of days to see if I can make them work) MClarke@mail.ocvts.org
Check your grades and complete any incomplete labs, quizzes, worksheets
Think of some simple games that you want to try and design for web pages next week (you have to give me a couple
of days to see if I can make them work) MClarke@mail.ocvts.org
Check your grades and complete any incomplete labs, quizzes, worksheets
Think of some simple games that you want to try and design for web pages next week (you have to give me a couple
of days to see if I can make them work) MClarke@mail.ocvts.org
Check your grades and complete any incomplete labs, quizzes, worksheets
Think of some simple games that you want to try and design for web pages next week (you have to give me a couple
of days to see if I can make them work) MClarke@mail.ocvts.org
Friday - English with Ms. Russen and Holiday Web Site Project
Classroom Discussion -
English - Ms. Russen will visit to discuss Cover Letters that accompany the résumé
Lab Assignment -
On-screen evaluation of this week's holiday web sites
Think of some simple games that you want to try and design for web pages next week (you have to give me a couple
of days to see if I can make them work) MClarke@mail.ocvts.org
Lab Assignment - Four days; four games; one per day. Then, thankfully, winter break:
Create a JavaScript web page to play the game "FORTUNE TELLER". The objective of "FORTUNE TELLER" is to
have the computer display random answers to player questions. The player will ask a question, click a button,
and the computer will randomly choose an answer to the player question. Some ideas:
Make up eight fortune answers to questions
Have a button for the player to click
Prompt the player for a question that the fortune teller will answer
Get a random number between 1 and 8 to randomly choose one of the eight answers
Display the question and the answer to the player
Have a button for the player to play again
Test frequently
Make it work
Make it look good
Create a JavaScript web page to play the game "TIC-TAC-TOE". The objective of "TIC-TAC-TOE" is to get three
in a row. Two players alternate play, choosing one of nine spaces arranged in a three by three grid. Some ideas:
Easiest is to click on a button and change the image to "X" or "O"
Draw a playing board of nine images arranged three wide by three high
Player X always goes first, clicks on one image, change that image to "X"
Player O goes next, clicks on another image, change that image to "O"
Alternate until one player wins or all nine images on the grid have been changed
Determine if you have a winner after each click image change
Give one point to the winner, player X or player O
Have a way to reset the grid to play again
Display current scores
Test frequently
Make it work
Make it look good
Create a JavaScript web page to play the card game "WAR". The objective of "WAR" is for two players
to play one card each randomly and compare them. The player with the higher card receives one point score.
After 26 cards have been played, the player with the highest score wins. Start with a normal deck of 52 playing
cards with four suits (Clubs, Diamonds, Hearts, Spades) and 13 cards in each suit (Two, Three, Four, Five, Six,
Seven, Eight, Nine, Ten, Jack, Queen, King, Ace). The computer will randomly deal 26 cards to two players.
Cards will be revealed two at a time, one from each player. The high card in each pair will win the round. Each
round results in a point to the winner. Ties are null; neither player wins the round. The player with the highest
score at the end of the 26 rounds wins overall. Some ideas:
Start with 52 cards
Get a random number between 1 and 52 to deal the first card to player 1
After dealing the first card, there are only 51 cards left in the deck
Reduce the size of the deck
Get a random number 1-51 to deal the next card to player 2
Repeat until no cards left
Each player receives 26 cards, randomly chosen. Leave them random
Take the first card from each player and compare them
The player with the higher value card gets a point added to his total
Ties are ignored, so it's possible for both player's scores to add up to less than 26
After 26 rounds, use the player scores to determine which player has won
Display outcome of game
Have a way to re-deal the deck so the players may play again
Test frequently
Make it work
Make it look good
Create a JavaScript web page to play the card game "BLACKJACK". The objective of "BLACKJACK" is for one
player to beat the computer, who is acting as the dealer, by adding the cards up and achieving a score closer
to 21 but not over. Start with a normal deck of 52 playing cards. The computer will randomly deal two cards to
a player and the computer (which will be the dealer). Player will see his cards but not the computer's cards.
Player may choose to receive additional cards [hit me], one at a time, up to a total of five cards. When the
player chooses to [hold], the computer will display its cards. The computer will decide to receive additional
cards while computer total is 16 or under. When the computer holds, the totals are calculated and the player
wins if his total is greater than the computer's, otherwise the computer wins. Play ends when all 52 cards have
been used. Some ideas:
Start with 52 cards
Use the technique from "WAR" described above
Randomly deal two cards to the player and two to the computer/dealer
Remember to reduce the size of the deck after each deal
Design a button for the player to receive additional cards [hit me]
Display each card value to the player as the card is received
Design a button for the player to choose to [hold]
Display the computer cards
Calculate the total of the computer cards
While 16 or under, randomly deal another card to the computer
Calculate the total of the player cards and computer cards to determine the winner of the hand
If the player total is higher than the computer total, without going over 21, the player wins a point
If the computer total is the same or higher than the player total, without going over 21, the computer wins a point
If player goes over 21, computer wins automatically and does not draw additional cards
If computer goes over 21, (can only happen if player is under 21 and [holds], player wins
Play again using the reduced size of deck
When the cards run out, determine a round winner one last time
Determine whether player or computer has a higher score
Display outcome of game
Have a way to re-deal the deck so the game may play again
CSS Dimension properties allow
control of the height and width of an element and the space between two lines
HTML DOM is a programming
interface for HTML documents and defines how you can access and change the content of HTML documents. DOM
stands for the Document Object Model
DOM Objects can have properties
with values and can respond to events and may be used in functions() to change styles
DOM Levels are separated into
three parts: Core, XML, and HTML
DOM Event Objects
represents the state of an event, such as the element in which the event occurred, the state of the
keyboard keys, the location of the mouse, and the state of the mouse buttons. The event object is
available only during an event - that is, you can use it in event handlers but not in other code.
DOM Anchor Objects An anchor
can be used in two ways: 1) To create a link to another document by using the href attribute or 2) To create a
bookmark inside a document, by using the name attribute. All Anchor objects in a document can be found in the
Document object's anchors array
Professional Development - Level 2.5 – Team Skills and Group Projects
CSS Classification properties
control how to display an element, set where an image will appear in another element, position an element relative
to its normal position, position an element using an absolute value, and the visibility of an element
DOM Form Objects are used to
prompt users for input. We may use form elements such as text fields, radio buttons, checkboxes and selection
lists. The input data is normally posted to a server for processing. Most DOM objects are stored in a form
elements array. You can access a the element by indexing this array - either by number (0 represents the
first element in a form) or by using the value of the name attribute
Classroom Discussion - Mr. Clarke absent, substitute teacher
Ms. DiPierro will visit and review math concepts for HSPA
Lab Assignment -
Math worksheet with Ms. DiPierro (AM class only)
Practice with JavaScript HTML Document Object Modules. Use forms and form objects:
Create a web page called "H:/JavaScript/dom/user.htm"
Add a textbox for user e-mail and validate it (example)
Add a textbox for userid and validate that it's exactly 8 characters (example)
Add a textbox for password and validate that it's exactly 8 characters (example)
Add three textboxs for telephone number area code-city-exchange and jump from
each when they're the properly filled out (3-3-4) (example)
Use radio buttons to ask the user if they want to receive e-mails (yes/no) (example)
Use check boxes to ask the user what type of e-mails they want to receive (updates/warnings/advertisements) (example)
Use an confirm pop-up message to allow the user to confirm their selections, except password (example)
Display all the user selections in a textarea box (example)
Do your best!!!
Test frequently
Make it work
Make it look good
Complete the "dom.htm" assignment from Monday
EXTRA CREDIT A Cool Million - How long to get to $1,000,000? Read the article
Want to Be a Millionaire? and create
an Excel spreadsheet to figure out how you can get to $1 million. If you deposit an amount of money regularly,
and let the interest compound without taking any withdrawals, your money will eventually start a tremendous
growth. Place labels to identify numbers on your spreadsheet. Rows will be years of savings. Columns will be
types of savings and Annual Percentage Rate (APR). Create a function and copy it to see how money grows:
Create a new Excel spreadsheet called "coolMillion.xls" and save it to your
"other assignments" folder
Create a heading area with labels:
In cell "A1" type "Initial Amount"
In cell "B1" type "Monthly Deposit"
Format cells "A2" and "B2" as currency
Put a dollar (1) in each ("A2" and "B2")
Type the label "APR" in cell "B3"
Type the label "Years" in cell "A5"
In cells "A6" through "A19" type the number of years as
"1", "2", "3", "4", "5", "10", "15", "20", "25", "30", "35", "40", "45", & "50"
In cells "B4" through "L4" type the savings types as "Savings", "CD 1 yr",
"CD 3 yr", "CD 5 yr", "Treasury", "Govt Bond", "Stocks", "Ford", "McDonald's", "Coca-Cola", & "Wal-Mart"
Get current MON-OC
Credit Union saving interest rates. I found these: "0.35%", "2.21%", "3.27%", "4.59%", "3.80%",
"5.30%", "11.00%", "15.00%", "18.00%", "21.00%", & "31.00%"
Create a function in cell "B5":
=FV(B$5/12,$A6*12,-$B$2,-$A$2)
The "$" is an "absolute" cell reference,
no "$" is a "relative" reference
Copy the formula from "B5" to "B6" through "B19"
Copy the formula from "B5" through "B19" to "C5" through "L5"
Highlight and format all columns for "AutoFit" so you can see the results
Does yours match mine?
Make it look good
Put your name on the top
Print and hand in
Try saving $2 per month, or even $5, how fast to earn $1 million?
How much would your money be worth without any interest? Create a column to track this
Create a JavaScript HTML DOM page with a smiley face, when the user moves the mouse over the smiley face, the
smiley face moves to a random position on the page. Call this "smiley.htm" and save it to your "H:/JavaScript/DOM" folder