160 likes | 251 Views
Explore object literals, reassigning variables, and swapping values in JavaScript. Learn key concepts like properties, methods, and the Date object. Practice with examples and enhance your coding skills.
E N D
CS110: Computer Science and the Internet - More JavaScript- Ex. on Far <->Cels- Objects- Object literals- Reassigning variables-Variable swap
Question 1 on the quiz • The expression 3+4*5 • A has the value 23 • B has the value 35 • C has the value 320 • D depends on the context
Review • Exercise • jQuery • http://cs.wellesley.edu/~cs110/lectures/JSprogramming/#bugs • $(selector).method(stuff); Let’s color all the <h2>’s blue $(‘h2’).css(‘background-color’, ‘red’); $(‘#box_id’).text(“Some text”)
Scott’s notes on Firebug • http://cs.wellesley.edu/~cs110/scott/L09-JS-dates/js-dates.shtml#stepping
Objectify the world! • Has (Properties) • Do (Methods) • Dog, Humans • JavaScript • Browser Window • Document • String • Date
The Date Object HAS DOES getDay() getMonth() getTime()
The Math Object DOES Random() HAS PI http://cs.wellesley.edu/~cs110/lectures/JSDatesEtc/#section_5
Let’s create Objects • var person1 = {name: "Alice", gradYear: 2013, going: "yes"}; • Object-literals • Firebug • http://cs.wellesley.edu/~cs110/lectures/JSDatesEtc/#js_object_literals
jQuery returns objects • Back to Scott’s notes • http://cs.wellesley.edu/~cs110/scott/L09-JS-dates/js-dates.shtml#section_5
Reassigning variables • var count = count + 2; • var answer = prompt (“What is your name?”); answer = “Scott”;
Variable swap • Misplaced letters • Let’s try it in Firebug
Your Questions • Do all methods have () at the end? And do all properties never have () at the end? • What is the difference between an object literal and an array? When would you use either? • Why do we use css in Javascript? (What would be examples of times that this would make sense?)
Shift gears • Back to Hex and Binary!
http://cs.wellesley.edu/~cs110/scott/L07-color-and-images/color-and-images.shtmlhttp://cs.wellesley.edu/~cs110/scott/L07-color-and-images/color-and-images.shtml
Hexadecimal Colors # 94 00 D3 RGB Using hexadecimal colors in CSS: blockquote { color: #9400D3; background-color: #E6E6FA; }