Sunday, February 17, 2013

PACS JavaScript February 16th, 2013 Math, Number, and Date Objects




    Objectives of Today’s SIG:
    • Picking up where we left off
      • Associative Arrays
    • Learning about
      • Math Object
      • Number Object
      • Date Object

    Arrays Con’t:
    • Using Associative Arrays
      • Also referred to as hash tables
      • Creating Custom properties

    Using Associative Arrays
    • Assign the tag MVP to one of the players on your roster.


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>PACS JavaScript SIG</title>
    </head>
    <body>
    <h1>PACS JavaScript SIG/</h1>

    <script type="text/javascript">

    // Usint Associative Arrays
    var positions = new Array();
    positions["3B"] = "Kevin Fandsen";
    positions["2B"] = "Chase Utley";
    positions["1B"] = "Ryan Howard";
    positions["SS"] = "Jimmy Rollins";
    positions["P"] = "Roy Halladay";
    positions["C"] = "Sebastian Valle";
    document.write("Playing First Base is "+positions["1B"]+"</br>");

    </script>

    </body>
    </html>


    Math Object:
    Like all Objects, the Math Object has properties and Methods. 

    • Math Properties
    Here are some examples of the Math Properites used during the SIG

    <script type="text/javascript">
    var bob = 1
    var math1 = bob * Math.PI;
    document.write("The value of PI "+math1+"</br>");

    //Use to calculate area of a circle
    var math2 = bob * Math.E;
    document.write("Euler's Constant "+math2+"</br>");

    /*  It is the limit of (1 + 1/n)^n as n approaches infinity, an expression that arises
    in the study of compound interest, and can also be calculated as the sum of the
    infinite series[2] */

    var math3 = bob * Math.SQRT2;
    document.write("The value of PI "+math3+"</br>");

    //square root of 2 is used in a 45degree triangle/pathagram theroy

    </script>

    • Math Methods
    We broke the Math Methods into three different groups
    • The Basic Methods
    • The Two-Parameter Methods
    • The Other Methods

    <script type="text/javascript">
    var bob = 4.5;
    var mathabs = Math.abs(bob);
    document.write("Here is "+mathabs+"</br>");
    var mathexp = Math.exp(bob);
    document.write("Here is "+mathexp+"</br>");
    var mathsqrt = Math.sqrt(bob);
    document.write("Here is "+mathsqrt+"</br>");
    var mathmx = Math.max(mathabs,mathexp);
    document.write("Here is "+mathmx+"</br>");
    var mathrnd = Math.round(mathexp);
    document.write("Here is "+mathrnd+"</br>");
    document.write("Here is "+bob+"</br>");
    </script>


    Number Object:
    • Number Object
      • Number Object Properties
      • Number Object Methods

    Number Object Properties:
    • MAX_VALUE
    • MIN_VALUE
    • NaN
    • NEGATIVE_INFINITY
    • POSITIVE_INVINITY

    <script type="text/javascript">
    // var num1 = 7.5
    var num1 = new Number(7.5);
    var num2 = new Number("127");
    var num3 = new Number("Bob");
    // sets up variable for display
    var num3a = Number.MAX_VALUE;
    var num3b = Number.MIN_VALUE;
    var num3c = Number.NEGATIVE_INFINITY;
    var num3d = Number.POSITIVE_INFINITY;
    document.write("The value of our variable is "+num1+"</br>");
    document.write("The value of our variable is "+num2+"</br>");
    var num4=num1+num2
    document.write(num4+"</br>");
    document.write("The value of our variable is "+num3+"</br>");
    document.write("The value of our variable is "+num3a+"</br>");
    document.write("The value of our variable is "+num3b+"</br>");
    document.write("The value of our variable is "+num3c+"</br>");
    document.write("The value of our variable is "+num3d+"</br>");

    </script>


    Number Object Methods:
    • toExponential()
    • toFixed()
    • toPrecision()
    • toSource()
    • toString()
    • valueOf()

    <script type="text/javascript">
    var num1=145.27456789
    document.write(num1.toExponential()+"</br>");
    document.write(num1.toFixed(3)+"</br>");
    //rounded to the specific number of digits after the decimal
    document.write(num1.toPrecision(3)+"</br>");
    //total number of characters not past decimal point
    document.write(num1.toString()+"</br>");

    </script>

    Date Object:
    • Date Object Properties
      • Constructor
      • prototype
    • Date Object Methods
      • A lot of them
      • Consult pg. 328 – 329 for list
      • Organize the Methods by their functions
        • Get Values
        • Set Values
        • Other
    <script type="text/javascript">
    var rightnow=new Date();
    var theday=rightnow.getMinutes();
    document.write("Today's date is "+theday+"</br>");
    </script>