JavaScript From Scratch: Playing With Data

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

    Favorites, Groups & Events

    JavaScript From Scratch: Playing With Data - Presentation Transcript

    1. JavaScript From Scratch “Playing With Data”
    2. Agenda • Strings • Numbers • Booleans • Arrays • Objects
    3. Strings • Any data surrounded by quotes • ‘Single quotes’ • “Double quotes” • Usually things with non-numeric characters
    4. Strings • Can be concatenated via the + operator var name = ‘Mike ’ + ‘Girouard’; var sentence = name + ‘ is awesome!’;
    5. var element = ‘p’; var content = ‘Hello, world!’; var tag = ‘<’ + element + ‘>’; tag = tag + content; tag = tag + ‘</’ + element + ‘>’;
    6. var element = ‘p’; var content = ‘Hello, world!’; var tag = ‘<’ + element + ‘>’; tag += content; tag += ‘</’ + element + ‘>’;
    7. Numbers • Any kind of number • 1, 2, 4, 100, 79812 (Integers) • 1.2, 7.9, 1.2489, 1.0 (Floats)
    8. var product = ‘Widget’; var price = 1.99; var quantity = 4; var taxRate = .08375; var subTotal = price * quantity; var taxAmt = subTotal * taxRate; var total = subTotal + taxAmt;
    9. Booleans • True/False values var canDrink = true; var canParkInBrooklyn = false;
    10. var isOver21 = (2008 - 1983) > 21; var isEmpty = (input.value == ‘’); var isIEorOpera = (‘all’ in document);
    11. if (isOver21) { alert(‘99 beers on the wall...’); }
    12. if (isEmpty) { alert(‘You missed something...’); input.focus(); }
    13. if (isIEorOpera) { var url = ‘http://getfirefox.com/’; window.location = url; }
    14. var validLogin = (user == ‘foo’ && pass == ‘bar’); if (!validLogin) { window.location = ‘bad-login.php’; }
    15. Arrays • One variable, multiple values • Use numbers to identify values • Think about an <ol> in XHTML • ... that starts with 0
    16. var colors = [‘red’, ‘green’, ‘blue’]; alert(colors[0]); alert(colors[1]); alert(colors[2]);
    17. var sentence = ‘There are ’ + colors.length + ‘ colors total’; colors.push(‘chartreuse’); sentence = ‘Now there are ’ + colors.length;
    18. Objects • Like arrays: one variable, multiple values • Instead of numbers, objects use strings
    19. var birthdays = { ‘Mike’ : ‘01-14-83’, ‘John’ : ‘06-23-74’, ‘Amy’ : null }; alert(birthdays.Mike); alert(birthdays.John); alert(birthdays.Amy);
    20. Review • Strings: • Begin and end with quotes • Quotes can be ‘single’ or “double” • Concatenated with a + operator • Appended with a += operator
    21. Review • Numbers: • Any kind of numeric data • Quotes are not necessary
    22. Review • Booleans: • true or false values • Form the basis of all logic in programming • Can be negated with a ! operator
    23. Review • Arrays: • One variable, multiple values • Indexed by numbers • ... beginning with 0 • New items can be added with push()
    24. Review • Objects: • One variable, multiple values • Indexed by strings
    25. Homework • Build a micro-library for HTML generation • Functions should accept arguments for each attribute • Functions should return strings as a result
    26. Homework • Required Functions: • a (href, title, content) • img (src, alt) • p, h1 ... h6 (content)
    27. Homework • Required Functions: • ol, ul (listItems) • dl (dictionary)

    + Michael GirouardMichael Girouard, 2 years ago

    custom

    1126 views, 0 favs, 1 embeds more stats

    The second of an eight part series covering the bas more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1126
      • 1084 on SlideShare
      • 42 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 29
    Most viewed embeds
    • 42 views on http://www.lovemikeg.com

    more

    All embeds
    • 42 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