Repl
https://repl.it/@ianmstew/FrightenedFlusteredExam
Codesandbox
- Users App (exercise): https://codesandbox.io/s/wo6yo6o0kk
- Users App (completed): https://codesandbox.io/s/508yx02q3l
Intro to Coding
-
Expression (value)
- Syntax that resolves to a value
- Like nouns: "Fox," "Dog"
- Like nouns with modifiers: "The quick brown fox," "The lazy dog"
- Like numbers: 1, 2, 3
- Like arithmetic with numbers: 1 * 2 + 3
- Like a placeholder for a value: "tomorrowsTemperatre"
"Hello"
-
Statement (action)
- Syntax that describes an action
- Made up of expressions
- Like sentences: "The fox jumped," "The quick brown fox jumped over the lazy dog"
- Like algorithm: Calculate the average of 1, 2, 3
- Like a command: "Check the temperature for tomorrow"
console.log("Hello");
-
Primitive values
- Series of letters/words, numbers, true/false
console.log("Hello"); console.log(1); console.log(true);
-
Operators
- Combine primitive values
- "Hello " + "Jane" -> "Hello Jane"
- 1 + 2 -> 3
- !true -> false
- true || false -> true
- true && false -> false
console.log("Hello " + "Jane"); console.log(1 + 2); console.log(!true); console.log(true || false); console.log(true && false);
-
Variables
- Containers for a value
- E.g., mini post-it inside of a larger post-it
- Age = 10, Name = "Jane"
var name = "Jane"; console.log(name); var janeAge = 12; var johnAge = 18; console.log(janeAge + johnAge);
-
Conditional statement
- Perform some action only if a certain condition is met
- "If the user's age is less than 13, then the price is $15; else, the price is $20"
var janeAge = 12; if (janeAge >= 18) { console.log('Jane is an adult'); } else { console.log('Jane is a youth'); }
-
Functions (named set of actions)
- A sequence of statements you want to use multiple times
- Like a recipe: Take 1 egg, boil for 10 minutes, cool under cold water, and you will have a hard boiled egg.
- Like an algorithm: Take a set of numbers, add them up, divide by the count of the numbers, and you will have the average.
- Like a service request: What is the forecasted temperature for tomorrow?
function logIsJaneAdult(age) { if (age >= 18) { console.log('Jane is an adult'); } else { console.log('Jane is a youth'); } } var janeAge = 12; logIsJaneAdult(janeAge); function isAdult(age) { if (age >= 18) { return true; } else { return false; } } var janeAge = 12; var isJaneAdult = isAdult(janeAge); if (isJaneAdult) { console.log('Jane is an adult'); } else { console.log('Jane is a youth'); } var johnAge = 18; var isJohnAdult = isAdult(johnAge); if (isJohnAdult) { console.log('John is an adult'); } else { console.log('John is a youth'); }
-
Arrays
- Sequences of values
- E.g., mini post-its inside of a rectangle on a piece of paper
- Ages = 10, 50
- Names = "Jane", "John"
-
Loops
- Run a sequence of statements multiple times.
- "Add up the price for all the users"
-
Objects
- Set of named values
- Almost like a variable of variables
- E.g., post-it with name and age followed by mini post-its containing values
- People = Name: "Jane", Age: 10; Name: "John", Age:
-
Array of objects
- Sequence of objects
- E.g., post-its inside of a rectange of a piece of paper