References Used


Uses and Limitations

JavaScript Terminology

Embedding JavaScript in an HTML Page

Debugging JavaScript

Variables, Operators, and Expressions


Input and Output

  • Input can be obtained in one of two ways:

    1. via form elements (to be discussed later)
    2. via the prompt function

      1. the prompt function pops up a dialog box with a text box and allows the user to enter a string of input
      2. the prompt function returns the string as its return value
      3. syntax: prompt("prompt message", default value)
      4. example: prompt("please enter sales tax rate", ".05");
      5. it is ok to provide an empty string, '', as the default value, or to simply omit the default value, in which case it will default to the empty string
      6. it is ok to provide any evaluable expression as the default value--the resulting value will be converted to a string
      7. if the user presses the "Cancel" button then prompt returns null
  • Output can be provided in a number of ways

    1. document.write(string): document is a pre-defined object and write is a method that writes a string. You can use the string concatenation operator, +, to concatenate several string fragments. You can write html markup in order to obtain formatted output.

      1. document.writeln will write a string with a newline attached to it but it is of limited utility because 1) the newline does not show up in the html output--<br> would be needed to do that, and 2) the source view will show the script, not the dynamically generated html so the string will not show up in the source view.

    2. alert(string): alert will pop up a dialog box with the given string value. Execution of the script will be suspended until the user presses the ok button.

    Ifs and Loops