JavaScript Goodies

JavaScript Goodies

Paperback(Older Edition)

$16.22 $19.99 Save 19% Current price is $16.22, Original price is $19.99. You Save 19%. View All Available Formats & Editions

Temporarily Out of Stock Online

Eligible for FREE SHIPPING


JavaScript Goodies by Joe Burns, Andree Growney, Andree Growney

JavaScript Goodies, Second Edition is based on the most popular JavaScript tutorials at It starts with the basics, including JavaScript syntax and common errors readers may encounter. It then continues with detailed lessons covering

  • Enabling mouse events
  • Using variables
  • Working with math operators
  • Writing loops

    Later chapters explain complex add-ons, including clocks and counters, passwords, and animation. The book finishes with a series of useful appendices readers can refer to for a quick reference of basic JavaScript features and commands.

  • Product Details

    ISBN-13: 9780789720245
    Publisher: Que
    Publication date: 06/02/1999
    Series: Other Programming Series
    Edition description: Older Edition
    Pages: 356
    Product dimensions: 7.24(w) x 9.04(h) x 0.91(d)

    About the Author

    Dr. Joe Burns is a professor of communications and the sole creator of the popular HTML Goodies Web site. He has been creating Web sites since the first version of Mosaic was released. Joe gets constant questions and feedback from his audience (over 150 e-mails a day!), and has used these insights to create better and better Web tutorials. Through HTML Goodies, he has taught hundreds of thousands of people how to build Web sites. His first book, HTML Goodies, has been very well received.

    Read an Excerpt

    Chapter 6: Mathematics, Random Things, and Loops

    Lesson 30: Math Operators

    This page will not only show you how to use numeric values to perform computation with JavaScript, but it will also test your basic math skills. There might be a test later. Its purpose is to introduce you to mathematical operators, something you'll use often. If you have done any type of computer programming before, you should be experiencing deja vu! If not, don't panic. Using this script, I'll give you an easy introduction:

     <SCRIPT LANGUAGE="javascript">

    var result = 10 * 2 + 1 3 - 7 alert ("the answer to 10 * 2 + 1 / 3 - 7 is " result + ".") var numsums = 10 + 2 alert("10 + 2 is + numsums) var x = 10 alert("ten is " + x) var y = x * 2 alert("10 * 2 = " + y) var z = "Hello " + "Good Bye" alert(z) </SCRIPT>

    The script's effect appears in Figure 6.1.
    To see the effect on your own computer click on Lesson 3 0 Script's Effect in your download packet or see it online at

    The Arithmetic Operators

    I think it would hard to get to this point in the book and not be able to figure this one out pretty quickly. But it's not the makeup of the script that's important. The purpose here is to show you the JavaScript binary operators.

    That's a fancy way to refer to the addition (+), subtraction (-), multiplication (*), and division (/) symbols.

    Percent (%) is also a binary operator. Its technical name is a modulus operator. However, it doesn't create percentages. You actually have to create the percentages by hand, dividing one number into the other. The percent sign only returns any number left over, a remainder, in a division equation.

    For example, the code 10 % 2 would return 0 because 2 divides into 10 evenly. But 10 % 3 would return the number 1. That's what's left over.

    Deconstructing the Super Math Script

    Well, maybe it's not super, but it makes its point.

    Each two-line piece of code sets up a mathematical equation or number usage and then uses an alert method to display the answers. Here's the quick rundown:


    We tried to create an equation that would use all the traditional binary operators. This is what came out. The answer is 13.333333333.

    Now, when you look at the equation it might seem that the JavaScript is doing the wrong calculation. If you pull out a calculator and follow the format, you might come up with this:

    10*2+1 (that equals 21) / 3-7 (that equals -4)

    Right? Well, JavaScript doesn't see it that way. Remember, we're dealing with a computer here. That computer just bulls through left to right without stopping to see this as a division problem. If you simply read the equation straight through, you'll get the answer the computer did:

    10*2 (equals 20) + 1/3 (a third) -7 = 13.333333

    So how do you get around the computer bulling through? Parentheses, my friend. Remember that from high school algebra? In math, the stuff in the parentheses is evaluated first. Same here. If I wanted to turn this into a division problem with an equation on either side of the slash, it would look like this:

    var result = (10 * 2 + 1) / (3 - 7)

    Be careful when you put together mathematical equations in your JavaScript. Make sure the computer is figuring out what you want it to figure out. Always check the math against a calculator before offering your work to the public.

     var numsums = 10 + 2 alert("10 + 2 is " + numsums) 

    The script sets a numsums variable. Can you see that it's equal to 12 (10+2)? The script transfers that variable to an alert box and displays that 10 + 2 = the variable, or 12.

     var x = 10 alert("ten is " + x) 

    Another variable, x, is set to equal 10. The alert box then displays that value.

     var y = x * 2 alert("10 X 2 = " + y) 

    Another variable, y, is set to equal the x variable multiplied by 2. That should be 20, right? It is. The answer is displayed in the alert method.

     var z = "Hello " + "Good Bye" alert(z) 

    Finally, the variable z is created, showing you can connect text using the computation symbols. That variable is then displayed using the alert boxes. That will become very important later on.

    The nice thing about the binary operator (+) is that it fulfils two duties. If it is placed between two numbers, it adds them. If it is placed between two strings, it puts them together into a single string, a process known as concatenation.

    In Terms of Numbers and Binary Operators

    Never put quotation marks around numbers. If you do put quotation marks around a number, it becomes a string. That's bad. For example, if you run the equation "3"+4, you will get 34 because the quotation marks made the "3" a string, and the plus sign simply put the two items together rather than adding them. If you want 7 to be the result, don't use any quotation marks so the plus sign sees both the 3 and the 4 as numbers.

    Your Assignment

    Write a script in which a prompt is used to ask the user for a number between 2 and 10. Then have that number's square display on the page.

    You do know what a square is, right? The number times itself.

    You can see a possible answer to this assignment on your own computer by clicking on Lesson 30 Assignment in your download packet or see it online at

    Table of Contents

    An Introduction by Joe Burns.

    Why Now? My Co-Author. How You Will Learn. The Format of the Lessons. Examples and Assignments.

    1. The Basics.

    What Is JavaScript? Lesson 1: Printing Text on a Web Page. Lesson 2: Error Messages. Lesson 3: Object Properties. Lesson 4: Chapter Wrap Up and Review.

    2. Popping Up Text with Mouse Events.

    Lesson 5: JavaScript's onMouseOver Event Handler. Lesson 6: More Event Handlers. Lesson 7: onUnload and onMouseOut, the After-Effect Commands. Lesson 8: HTML 4.0, the SPAN Flag, and Some New Event Handlers. Lesson 9: Let's GO! Lesson 10: The Second End of Chapter Review.

    3. Manipulating Data and the Hierarchy of JavaScript.

    Lesson 11: Prompts and Variables. Lesson 12: Dates and Times. Lesson 13: Hierarchy of Objects. Lesson 14: Creating a Function. Lesson 15: An Introduction to Arrays. Lesson 16: The Third End of Chapter Review—A BODY Flag Script.

    4. Flipping Images and Opening Windows with Mouse Events.

    Lesson 17: An Image Flip Using onMouseOver and Pre-Loading Images. Lesson 18: An Image Flip with a Function. Lesson 19: Opening New Windows. Lesson 20: Opening a Window with a Function. Lesson 21: The Confirm Method, with an Introduction to If and Else. Lesson 22: The Fourth End of Chapter Review— Some Jumping Jacks.

    5. Forms: A Great Way to Interact with Your Users.

    Lesson 23: What Is Written in the Text Box? Lesson 24: Passing Information to the Function. Lesson 25: Calling Functions with Forms. Lesson 26: Form Fields and the Value Property. Lesson 27: Pull-Down Menu of Links. Lesson 28: A Guestbook with All the Bells and Whistles. Lesson 29: The Fifth End of Chapter Review—Posting Link Descriptions While Users Pass Over.

    6. Mathematics, Random Things, and Loops.

    Lesson 30: Math Operators. Lesson 31: Mathematics and Forms. Lesson 32: Creating Random Numbers with a Date. Lesson 33: Creating Random Numbers Through Mathematics. Lesson 34: Producing Random Statements and Images. Lesson 35: Introduction to for Loops. Lesson 36: Introduction to while Loops. Lesson 37: End of Chapter Review—A Browser Detect Script.

    7. Clocks, Counts, and Scrolling Text.

    Lesson 38: A Running Clock. Lesson 39: A Fancy Digital Clock. Lesson 40: Image Driven Clock. Lesson 41: Countdown to Date. Lesson 42: Scrolling Text. Lesson 43: End of Chapter Review—Count to an Event.

    8. Arrays.

    Lesson 44: Two Different Array Formats. Lesson 45: Combining User Input with Arrays. Lesson 46: Random Quotes. Lesson 47: A Guessing Game Using Arrays. Lesson 48: A Password Script. Lesson 49: End of Chapter Review—A Quiz.

    9. Putting It All Together.

    Lesson 50: JavaScript Animation. Lesson 51: Background Color-Changing Script. Lesson 52: A Floating, Moving, New Browser Window. Lesson 53: Form Validation. Lesson 54: Self-Typing Typewriter. Lesson 55: Scrolling Credits.

    Appendix A. JavaScript Basic Concepts.

    Literals. Boolean Literals. Comments. Document Object Model. Event Handlers. Literal Integers. Methods. Objects. Operators. Properties. String. Variable.

    Appendix B. JavaScript Command Reference.

    action Property. alert Method. alinkColor Property. appCodeName Property. appName Property. appVersion Property. array Method. back Method. bgColor Property. big Method. blink Method. bold Method. close Method. confirm Method. Date Object. defaultStatus Property of window. document Object. document Property. eval Method. fgColor Property. fixed Method. fontcolor Method. fontsize Method. for Loop. forward Method. frames Property. function Object. getDate Method. getDay Method. getFullYear Method. getHours Method. getMinutes Method. getMonth Method. getSeconds Method. getTimezoneOffset Method. getYear Method. go Method. history Object. host Property. hostname Property. href Property of location. if / else. indexOf Method. italics Method. lastModified Property. length Property. linkColor Property. location Object. location Property. Math Object. navigator Object. onBlur Event Handler. onChange Event Handler. onClick Event Handler. onDblClick Event Handler. onFocus Event Handler. onKeyDown Event Handler. onKeyUp Event Handler. onLoad Event Handler. onMouseDown Event Handler. onMouseMove Event Handler. onMouseOut Event Handler. onMouseOver Event Handler. onMouseUp Event Handler. onSelect Event Handler. onSubmit Event Handler. onUnload Event Handler. open Method. parent Property of frame and window. pathname Property. port Property. prompt Method. <F102MO>protocol Property. referrer Property. self Property. selectedIndex Property. setDate Method. setHours Method. setMinutes Method. setMonth Method. setSeconds Method. setTime Method. setTimeout Method. setYear Method. small Method. status Property. strike Method. sub Method. substring Method. sup Method. title Property. toLowerCase Method. <F102MO>toUpperCase Method. userAgent Property. <F102MO>value Property. <F102MO>var Variable. vlinkColor Property. while Loop. window Object. write Method. writeln Method.

    Appendix C. JavaScript Reserved Variable Words.

    Appendix D. Scripts Available on

    Alert Scripts. Buttons, Links, and Email Scripts. The Three C's: Clocks, Calendars, and Calculator Scripts. Color Scripts. Game Scripts. HTML and Developer Scripts. Image Scripts. Scrolling Scripts. Text-Based Scripts. Miscellaneous Scripts.


    Customer Reviews

    Most Helpful Customer Reviews

    See All Customer Reviews

    JavaScript Goodies 3 out of 5 based on 0 ratings. 7 reviews.
    yogi_123 More than 1 year ago
    Nice experience...
    Guest More than 1 year ago
    I've been to Joe Burns' (the primary author) web site many times, before, and it actually introduced me to HTML. I learned a lot from that site, and after I'd learned everything I possibly could about HTML, I wanted to take it a step further and go into Dynamic HTML (DHTML). I knew JavaScript was the easiest to write and use, and since I knew our friend Joe had written a big fat book on it, I decided that it was the way to go. You absolutely must know a great deal of HTML to use this book, or any book for that matter. JavaScript shouldn't stand alone, and the book's examples and assignments do not exclude HTML source code. If you know HTML, you'll have an easy time learning JScript, if not, you won't get past Chapter 1, I guarantee it. Now that I've scared away the non-HTML folks, here's my enthusiastic review of the book: The book goes at a nice pace, fairly slow, because unlike HTML, JavaScript is a programming language. Because unlike HTML, JavaScript has conditional statements, variables, functions, loops, and a lot more. It really is a lot harder than HTML, but not as hard as the big bad languages like ASP and C++. Essentially, however, the pace goes on a curve. At the beginning you sort of dwell on small things longer, and do easier things with the concepts. Later on, though, you take things at full speed. Once the foundation is there, you'll start absorbing it like a sponge; pardon the trite simile there. Like the heading above would suggest, this book only covers beginning and intermediate JScript, so if you plan on decrypting some cool scripts you found, you'll probably only half-accomplish that goal. But don't leave just yet- what's in the book is the majority of JavaScript, and what's in the book is extremely well-written and easy to follow. This is probably because Joe is not exactly some programming wizard who knows all the languages. He's an ordinary guy, and he's a bit of a redneck to boot. We'll forgive him for his lack of knowledge of the order of operations, what a reciprocal is, and the fact that noon is not AM. Yes, he made all those errors, at one point criticizing computers (OH, NO!) for 'bulling through' equations, when the browser was really following the order of operations. Please excuse my dear Aunt Sally, for those of us who've forgotten it from junior high. Sorry, I like to ramble. In a nutshell, here's my review. Joe's easy to understand, he wrote it well, and it's taken at a slow pace. The assignments at the end of each lesson (each concept is its own lesson) and chapter are excellent practice, and greatly further your learning. At the end of the book you'll find reference, and ten cool scripts for commonly-requested tasks, like cookies, banner rotation, and more. You'll want to learn the advanced stuff when you're done, but until then, you'll really be glad you bought this book. I guarantee it.
    Guest More than 1 year ago
    Total junk. Worst programming book I've ever bought. Period. Code doesn't work half the time, poorly written, hokey presentation . . . PLEASE avoid this book!
    Guest More than 1 year ago
    There are some interesting scripts in this book. However, many scripts aren't practical. There are many spelling mistakes and since Javascript is case-sensitive, those mistakes are unacceptable.
    Guest More than 1 year ago
    This book made javascript easy to learn. However, I feel that if you didnt know much or nothing about java then things could have gotten scetchy there in the middle. Otherwise it helped me learn js quickly and easily.
    Guest More than 1 year ago
    This book might be O.K. for an absolute beginner, but anyone who has any programming experience of any kind should stay away. The author clearly has no idea about basic programming concepts because he sounds amazed by simple concepts such as variables, arrays, methods, and objects. Here are a few examples: In several places the author writes an if statement that will always be true so that 'we know the condition will run.' Huh? Obviously, if it is always true there is no need to have it! (See page 241 if you don't believe me.) Another example is the authors lack of understanding of the concept of operator precedence. He actually claims that '10 * 2 + 1 / 3 - 7' will evaluate 'left to right.' (See page 142 is you think I'm joking.) He also makes utterly stupid comments like, 'JavaScript counts everything,' again and again throughout the book. This book is totally worthless as a reference, but I thought it would at least have some cool scripts. Wrong! The scripts are very basic and generally not very useful. Don't be fooled by this book's low price either. It's not worth it! You will have to buy a real JavaScript book later anyway.
    Guest More than 1 year ago
    Joe Burns has absolutely outdone himself. If you are even mildly proficient with HTML and want to expand your skillset and really make your web pages come to life, then Javascript Goodies is the book for you. I've now read about 8 books about various web-talks: Java Applets, Javascript, CSS, HTML 4.0, DHTML, ASP.... This is by far the easiest book to read, yet also has a rapid curriculum which means you can have javscript electrifying your pages in minutes....literally! I can't say enough good things about this book. If you don't know javscript, muster up the courage to give it a whirl with Javascript Goodies and you won't be sorry.