- What is the outcome of the following expressions?
- true || false
- false && false
- true && false
- (false || true) && true
- false && ((true || false) && (false || true))
- Which of the following are truthy values? (hint: try
if("abc"){console.log("I'm truthy!")}
in the JS console)
- 1
- 0
- 3.14159
- "abc"
- ""
- Array
- []
- Object
- {}
- What is the outcome of the following expressions?
- true && 6
- 0 || "hi"
- ["a","b","c"] || "123"
- {"key":"value"} || false
Remember, you can work in a file (like controlFlow.js) in Sublime Text to keep your code. Run it from the terminal by typing node controlFlow.js
, or copy and paste sections into the Chrome developer console.
Jimmy loves roller coasters, but there are a bunch of rules (ugh!) for riding:
For starters, it costs 5 tokens. Here's how we might code that:
var tokens = 3; // Jimmy's tokens
// Can he ride?
if ( tokens >= 5 ) {
console.log("Step right up!");
} else {
console.log("Sorry, you can't ride")
}
Edit the code above to check the following additional Requirements:
- Must be at least 4ft tall.
- Must be at least 12 years old.
- Replace the previous rule: now riders under 12 must be accompanied by an adult.
- If the boss isn't looking, you can sneak in!
- Riders with a park pass get in free.
- Log to the console "This is awesome!" 25 times.
- Create a new variable that is an array of 4 phrases:
"Howdy there"
,"OMG"
,"javascript"
, and"Pair Programming"
. - Loop over the array and log each phrase to the console.