Skip to content

Instantly share code, notes, and snippets.

@Shurlow
Last active June 23, 2018 07:19
Show Gist options
  • Select an option

  • Save Shurlow/9f96acc0bd30e9f289e36ea8cfc9ac23 to your computer and use it in GitHub Desktop.

Select an option

Save Shurlow/9f96acc0bd30e9f289e36ea8cfc9ac23 to your computer and use it in GitHub Desktop.
Iteration & Conditionals Lesson Notes

Iteration & Conditionals

Objectives

  • Use if / else if / if to write conditional code
  • Identify the syntax of standard for loops
  • Write for loops
  • Write while loops
  • Loop over an array
  • Loop over an object

Guiding Questions

  • What will the following code snippets print out?

    if (2 > 1) {
      console.log('A');
    } else {
      console.log('B');
    }

    Your answer...

    if (2 > 1 && 5 <= 3) {
      console.log('C');
    } else {
      console.log('D');
    }

    Your answer...

    if (7 % 2 === 0 || Number.isInteger(3.4)) {
      console.log('E');
    } else if (6 <= Math.floor(5.8)) {
      console.log('F');
    } else {
      console.log('G');
    }

    Your answer...

    Practice

    Complete the challenges in this lesson: https://learn.galvanize.com/cohorts/650/units/7294/content_files/82809

  • What is a for loop used for in javascript?

    Your answer...

  • Looking at the following example, idetify the 5 main parts of the for loop:

    1. keyword
    2. initial step
    3. condition
    4. increment step
    5. body
    
    for(var i = 0; i < 5; i++) {
      console.log(i)
    }

    Your answer...

  • What is a while loop used for in javascript? When would you use a while loop instead of a for loop?

    Your answer...

    Practice

    Complete the challenges in this lesson: https://learn.galvanize.com/cohorts/650/units/7294/content_files/82807

Looping over Arrays and Objects

Resources

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment