Basics Syntax for invoking methods in the object



Yüklə 358 Kb.
tarix07.11.2018
ölçüsü358 Kb.
#78684


Javascript/Jscript Ch 7,8,9,10


Introduction



Basics

  • Syntax for invoking methods in the object

    • 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



Windows, Documents and String handling



Output



JavaScript is Loosely Typed



Math Object Compound Interest



Script Output



Switch Statement



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:



Form Event Handling

  • Clicking on GUI button element causes an action

    • Function indicated is executed when button clicked
    • Any user interaction with a GUI is called an event
    • Event handling – JavaScript execution in response to an event
    • GUI’s are located in the BODY of the HTML document


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)



Assignment - Javascript



Yüklə 358 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə