


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Topics Covered
JavaScript: Object-Based Language
Scripting
1 2 4 5 6 7 8 9 10 A First Program in JavaScript 11 12 18 19 20
1 2 4 5 6 7 8 9 10 Printing a Line with Multiple Statements 11 12 19 20 21
Escape character in combination with quotation mark: \” will result in insertion of a quotation mark in the string that is actually written by JavaScript
1 2 4 5 6 7 8 9 Printing Multiple Lines in a Dialog Box 10 11 16 17 18 19 20
Click Refresh (or Reload) to run this script again.
21 22alert method of the object displays a Dialog
Dynamic Pages
the user or other information
of a window object
1 2 4 5 6 7 8 9 10 Using Prompt and Alert Boxes 11 12
“+” symbol can be used for text concatenation as well as arithmetic operator
This is the prompt to the user.
This is the default value that appears when the dialog opens.
This is the text field in which the user types the value.
When the user clicks OK , the value typed by the user is returned to the program as a string.
If the user clicks Cancel , the null value will be returned to the program and no value will be assigned to the variable.
Simple Script Example: Adding Integers
24 // read in second number from user as a string 25 secondNumber = 26 window.prompt( "Enter second integer", "0" ); 27 28 // convert numbers from strings to integers 29 number1 = parseInt( firstNumber ); 30 number2 = parseInt( secondNumber ); 31 32 // add the numbers 33 sum = number1 + number2; 34 35 // display the results 36 document.writeln( "The sum is " + sum + "" ); 37 // --> 38 39 40 41 42
Click Refresh (or Reload) to run the script again
43 44