JavaScript from Scratch: Getting Your Feet Wet

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    JavaScript from Scratch: Getting Your Feet Wet - Presentation Transcript

    1. JavaScript From Scratch “Getting Your Feet Wet”
    2. Agenda • Variables • Conditionals • Loops • Functions
    3. Variables are... • Storage Containers for Data • Someone’s name • A username/password • The current time • ... or anything else your application needs
    4. var password = ‘mike is awesome’;
    5. var name = ‘Mike G’; var age = 25; var isCool = true;
    6. Conditionals are... • A way to execute code conditionally • If something is true, do this • Otherwise, do that
    7. var age = 25; if (age < 21) { alert(‘Go home’); }
    8. var age = 25; if (age < 21) { alert(‘Go home’); } else { alert(‘Two drink minimum’); }
    9. Loops • Loops allow code to run repeatedly • Over and over and over... • But only upon a condition
    10. var start = 10; var stop = 20; var counter = start; while (counter <= stop) { alert(counter); counter = counter + 1; }
    11. About those operators = var foo = 100;
    12. About those operators == (foo == 100)
    13. About those operators < (age < 21)
    14. About those operators > (calories > 2000)
    15. About those operators <= (age <= 21)
    16. About those operators >= (calories >= 2000)
    17. About those operators && (age >= 25 && age <= 50)
    18. About those operators || (name == ‘mike’ || name == ‘joe’)
    19. Functions • Store “blocks” of code so they can be reused later • Are one of the most powerful features of the JavaScript language
    20. function add () { alert(2 + 2); } add();
    21. function add (num1, num2) { alert(num1 + num2); } add(2, 2); add(42, 10); add(123, 0);
    22. function add (num1, num2) { return num1 + num2; } var sum1 = add(2, 2); var sum2 = add(42, 10); var sum3 = add(123, 0);
    23. Review • Variables... • Store data • Begin with a var • Are given names • Are assigned values with =
    24. Review • Conditionals... • Fork code execution based on a condition • Begin with an if • Condition enclosed in (parenthesis) • Blocks are enclosed in {curly braces}
    25. Review • Conditionals... • Can use else to catch a failed conditional
    26. Review • Loops... • Repeatedly execute blocks of code • Execute conditionally • Come in many flavors: • while, for, for in, do while
    27. Review • Functions... • Store code for later use • Can accept input parameters (arguments). • Can send output (return values).
    28. Homework • Build a micro-library which performs basic math operations • Functions should accept arguments and return the result of the math operation
    29. Homework • Required Functions: • add (num1, num2) • subtract (num1, num2) • multiply (num1, num2) • divide (num1, num2)
    30. Homework • Required Functions: • square (num) • increment (num) • decrement (num) • power (num, power)

    + Michael GirouardMichael Girouard, 2 years ago

    custom

    1367 views, 2 favs, 1 embeds more stats

    The first part of an 8 part series covering the bas more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1367
      • 1310 on SlideShare
      • 57 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 46
    Most viewed embeds
    • 57 views on http://www.lovemikeg.com

    more

    All embeds
    • 57 views on http://www.lovemikeg.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags