Javascript/Jscript Ch 7,8,9,10
Introduction
Basics - object.method( “string”, “[additional arguments]” );
document.writeln( “argument” ); - C like syntax
- Uses the writeln method in the browser’s document object
tag: - Encloses entire script
- Attribute LANGUAGE = “JavaScript”
Document Object
Window Object
Windows, Documents and String handling
Output
JavaScript is Loosely Typed
Math Object Compound Interest
Script Output
Switch Statement
Switch Script Output
A Game of Chance - “CRAPS” Rules of “craps” - Player rolls 2 dice (6 faces/die, range: 1-6)
- Sum of spots on two upward faces calculate
- If sum equals 7 or 11 – player wins
- If sum equals 2, 3 or 12 on first throw (called “craps”) – player loses
- If sum equals 4, 5, 6, 8, 9 or 10 on first throw – sum is players “point”
- If game not over after first roll, player continues rolling
- If rolls sum equal to his “point” – player wins
- if rolls 7 before matching his “point” – player loses
- Player continues rolling until game is over
Input from Forms Program can receive input from user through forms GUI Form Setup using Form:
Clicking on GUI button element causes an action
Form Data output Program can output results to a form - Within a function, write a statement in the following format:
- formName.InputName.value = Value to be output;
Outputing results to the Browser Status Bar - Print text by typing
- window.status = “text to be printed”;
Script Output 1 (player wins first roll)
Script Output 2 (player loses first roll)
Script Output 3 (player wins on second roll)
Script Output 4 (player loses on second roll)
Dostları ilə paylaş: |