Summer Institute For The Gifted
Classes taught by Maureen L Greenbaum

Drew University
June 30 - July 20, 2002

Home
Art
Web Design
Programming

Mail

Programming Problems

Concepts
  • Remember to end every line with a ; semicolon.
  • caPitaLizaTion counts!  var is correct VAR is not!
  • Balance {} and () and "" and ''
    {} are use to enclose the stuff done in a while, for, do, switch and if
    () are use to enclose the "when??" or test of if, while and do
    () are used to enclose the parameters of methods such as alert, prompt and writeln
    an object and its method are separated by a . (period/dot)  document.writeln or window.status
  • document what you are doing with comments, you'll be glad later
  • // signals to JavaScript everything remaining on the line is a comment
    /* begins a Javascript comment that can be as long as you want */ ends it
    <!-- begins an HTML comment and --> ends it
    Concise Javascript ReferenceprojectCool has an excellent 2 page summary of objects/methods and operators

Methods
alert

Say Hello: Using alert tell the world Hello

prompt Ask: Using prompt and alter, get your name and then say Hello to yourself.
writeln writeln Using prompt and write, get your name and then say Hello to yourself. Remember to put <br> at end of line
math

parseInt
function
Sum: Using prompt and write, get 2 numbers and print their sum.
subtract: Using prompt and write, get 2 numbers and print their difference.
multiply: Using prompt and write, get 3 numbers and print their product.
average Using prompt and write  (or alert) , get 3 numbers and print their average.
if/case
toUpperCase
State capital: Make a page with either maps or pictures of famous places that identify a state. (use the ClipArt Gallery or search the web).  Make it a hyperlink and use onClick event to invoke a function that requests the state name and tests if the answer is correct (use toUpperCase method to permit upper and lower case).  The if the answer is correct, request the capital or state bird or whatever (use Welcome to the 50states.com web site. The number one link resource for states research. 
Thanks for visiting. Tell two friends. for data).  Try as an array when you have 50 to do!
Case
Date
date methods
 

Good Morning: Using the system date, say "Good Morning", "Good Afternoon or Good Evening" to yourself upon loading your page.

Hints.  First make a date object, then extract the hour using the getHours method.  Then use IF or switch/case too test if it is after midnight but before noon, afternoon but before dinner (7pm which is 19 army time)    solution

for

Growing Text: Render text with ascending font sizes (from font size 1 to 7), starting over when it hits 7.
(Great and efficient way of sprucing up selected messages on your site!)    solution
Example:
WELCOME TO OUR SITE!WELCOME TO OUR SITE!

case
while
 

Pass/Fail count: Enter numeric student grades until an negative grade is entered.  Count the number of pass grades and failures (60 or over pass).
Display the answer.
Remember to output instructions before requesting values.

Dietel, Dietel, Nieto Internet& World Wide Web-How to Program, p308

Hint: Create the prompt then if for one student first, them put in a while or do/while loop

case
while

 

Grades: Using case count the A's (90 or more), B's (80 to 89), C's, D's and F's (59 and under)

Hint
var choice = window.prompt(); switch ( choice )
{ case “a”:
     actions  
  case “b”:
     actions  case “z”:      actions  default:     actions }

case

array

Day of the Week: using date and getDay method print out the day of the week.  Try if first using a switch/case then try putting the days of the week into an array and printing the correct array.   case solution array solution
onLoad

onUnload

When a visitor leaves your site, alert them how long they have been viewing the page.
input
function
solution
onmouseOver
onMouseOut

Window.status

Helpful Message: Display a helpful message on the status bar when the mouse hovers over a hyperlink.  Display a different one when the cursor exits.  explanation
onload
onunload
onblur
 
Images see the birdie change size.  Now do it with a MouseOver and MouseOut.  And try continually using a setTimeout(). 
Images
Array
see the joggerer run. use the individual pictures
Images
array
if
see the rocking horse.use the individual pictures
setTimeout
clearTimeout
getHours
getMinutes
getSeconds
value property
Clock: Create a clock that displays the time  
Hints: set a time onLoad, clear it on onUnload.  Create a date/time object that contains the system date/time.  Extract the houses, minutes and seconds using getHours, getMinutes, getSeconds.  Concatenate them into a variable with some ":" separating the pieces.   Display it by setting the value of a input text box.                  solution also works
String Object
Methods
bold()
italics()
fontcolor()
fontsize()
substring()
subst()
Hints: substring()

 

Sumware in NJSite creation and maintenance by Maureen Greenbaum of  Sumware in NJ
This page last modified May 03, 2008
©1997, 98, 99, 2000, 01, 02, 03, 04, 05, 06, 07, 2008 SUMWARE in NJ, Watchung, NJ