Skip to content

murcielago17/control-flow-exercises

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Control Flow Exercises

Boolean Expressions and Truthy Values

  1. What is the outcome of the following expressions?
  • true || false
  • false && false
  • true && false
  • (false || true) && true
  • false && ((true || false) && (false || true))
  1. 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
  • {}
  1. What is the outcome of the following expressions?
  • true && 6
  • 0 || "hi"
  • ["a","b","c"] || "123"
  • {"key":"value"} || false

Conditionals!

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:

  1. Must be at least 4ft tall.
  2. Must be at least 12 years old.
  3. Replace the previous rule: now riders under 12 must be accompanied by an adult.
  4. If the boss isn't looking, you can sneak in!
  5. Riders with a park pass get in free.

Loops!

  • 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.

About

Control flow exercises for week 1 day 3 module 1.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published