140 likes | 225 Views
Introduction to Programming (in JavaScript). David Stotts Computer Science Department UNC Chapel Hill. The Big Six. 0. data ( types, simple information ) 1. data storage ( variables, assignment ) 2. data retrieval ( expressions, evaluation ) 3 . repetition ( loops )
E N D
Introduction to Programming(in JavaScript) David Stotts Computer Science Department UNC Chapel Hill
The Big Six 0. data (types, simple information) 1. data storage (variables, assignment) 2. data retrieval (expressions, evaluation) 3. repetition (loops) 4. decision making (conditionals) 5. procedure abstraction (functions) 6. data abstraction (arrays) 7. objects: all-the-above, wrapped up
0. Databefore the big 6 there is an item 0 • We can’t study data storage and retrieval without knowing what “data” is Datathe basic symbols and information that a computer manipulates • Data is why we write programs in the first place… we have questions, we want answers • Want information we have (input) turned into new information we need (output)
Data Input information we have and want a program to work on… we have to get it from the user and make it available to the program, in the computer memory Output the new info we expect the program to produce, to generate, to compute… we have to get it out of the program and back to the user in a form the user can consume and employ I/O is the term we use
Von Nuemann Model of a Computer computer I/O Cloud, etc.
DataJavaScript native types, “built in” Number 4, 10, -23, 729358, -414, 0 3.14159, -21.15, 7.0, 1101.1 5.3e7 17.336e-14 0.000031 integers and reals
DataJavaScript native types, “built in” String “tarheels” “x” “3.14159” “(919) 555-1212” “xp @ aol.com” “hola ! !” “$ntko # &”
DataJavaScript native types, “built in” Boolean • true, false (yes, no) are the only values • the basis for “logic”
Dataoperations on native types Number + - / * % 4+5 9 23.4 + 9.3 32.7 -2 * 7 -14 3.4 – 1.1 2.3 7/2 3.5 53 % 12 5 “mod”
Dataoperations on native types Text + concat substring “abc” +“123” “abc123” we call this concatenation “abc”.concat(“123”) “abc123” “tarheels”.substring(3) “heels” “tarheels”.substring(0,2) “tar”
Dataoperations on native types Boolean && || ! true && true true AND true && false false false && false false true || false true OR true || true true false || false false !false true NOT !true false
Dataoperations on native types Comparisons 5 < 8 true less than 17 <= 3.28 false less than or equal 21.4 > -34 true greater than 1.0 >= 1.1 false greater than or equal 12.3 == 2.8 false equal to -3 != -3.1 true not equal to
Dataoperations on native types Comparisons work on strings too “hello” < “world” true alpha order-ish “bigfoot” > “big” true “tar” == “tarheels” false “tar” < “tarheels” true (it’s shorter) “Upper” != “upper” true case matters “upper” > “Upper” true (seems strange) “5” > “4” true these are not numbers “5” > “40” true remember… alpha order