Title: Creating a dynamic page with random photos
1Creating a dynamic page with random photos
- Madeline Ortiz-Rodríguez
- September 8, 2003
2Objectives
- To create a simple web page with JavaScript code
in Dreamweaver, so that pictures are presented
randomly. - Example
- http//plaza.ufl.edu/mortizro/DimeLesson/photo.htm
l
3JavaScript
- JavaScript is not the same as Java.
- The code is included where you want an action to
appear in the web page. - In JavaScript you start counting with the number
zero (0). - JavaScript is case sensitive.
- Be careful with spaces and quotation marks.
4Random photos code
var num Math.round(1 Math.random()) var
photonum if (photo0) document.write("ltimg
src'photo1.jpg' width200 height150gt") else
if (photo1) document.write("ltimg
src'photo2.jpg' width200 height150gt")
5Math.random( )
- Random numbers in JavaScript run from .000 to
.999 - There are one thousand random numbers in
JavaScript. - To find random numbers we multiple by an integer.
For example - 1 Math.random()
6Math.round( )
- Rounding a random number will convert it into an
integer (a whole number). - For example
- 0.499 0
- O.525 1
- 2.709 3
- The instruction Math.round(1 Math.random())
- Will provide two random numbers 0 and 1
7Document.write( )
- Code that allows to place text or images on the
screen. - Inside the quotation marks you write HTML codes.
- If you need to use quotations again, use
apostrophes instead of quotation marks. For
example - document.write(ltimg src'photo1.jpg'gt)
8Changing the code
- Number of photos
- Adding extra code
9References
Burns, Joe. (1999). JavaScript Goodies. IN QUE.
Lesson 33 Creating Random Numbers Through
Mathematics Burns, J. Growney, A. The
JavaScript Primers 30 Steps that make
JavaScripting fun to learn! http//www.htmlgoodies
.com/primers/jsp/ The JavaScript Source.
http//javascript.internet.com/