Loopin'

Codepen Instructions

Create a new CodePen pen.

Instructions

  • Create an array of 5 of your interests.
  • Loop through the interests and console log the phrase "One of my interests is: [your interest]." for each of the interests in your array.
  • Pick your favorite interest. Add an if statement in your loop that checks each time if the interest is your favorite interest. For the one item that is your favorite, console log "My absolute favorite interest is: [your favorite interest]." Still console log the message for each of your other interests from the step above.

Output

One of my interests is: hiking.
My absolute favorite interest is: coding.
One of my interests is: math.
One of my interests is: 30 Rock.
One of my interests is: pizza.

Level 1: I Can Function

Codepen Instructions

Create a new CodePen pen.


Instructions

  • Write a function named printPersonalizedMessage.
  • The function should take two parameters: user's name and user's favorite color.
  • The function should print out a message to the user: "Hey, [user's name], I see you like [user's favorite color]."
  • Call the function using your name and your favorite color.
  • Try calling the function with other names and other favorite colors and watch how it changes the output.

Result

Console:
"Hey, Callan, I see you like orange."

Level 2: Temperature Conversion

Codepen Instructions

Create a new CodePen pen.


Instructions

You'll be writing two functions: one that converts Celsius to Fahrenheit and the other, vice versa.

Celsius to Fahrenheit
  • Write a function that takes the temperature in Celsius as the parameter
  • The function should do the following calculation to get the temperature in Fahrenheit: T(F) = T(C) * 1.8 + 32
  • Output the temperature in Fahrenheit to the console
Fahrenheit to Celsius
  • Write a function that takes the temperature in Fahrenheit as the parameter
  • The function should do the following calculation to get the temperature in Celsius: T(C) = (T(F) - 32) / 1.8
  • Output the temperature in Celsius to the console

Result

Console:
"You entered [degrees in Celsius] Celsius. That converts to [degrees in Fahrenheit] Fahrenheit." "You entered [degrees in Fahrenheit] Fahrenheit. That converts to [degrees in Celsius] Celsius."

Level 3: Sum & Product

Codepen Instructions

Create a new CodePen pen.


Instructions

You'll be writing a function that accepts an array of numbers and adds them up.

  • Create a variable with an array of numbers.
  • Create (declare) a function named addUpAllTheseNumbers.
  • The function should accept one argument: an array of numbers.
  • The function should have a for loop that loops over the array of numbers parameter and adds them to a running sum.
  • The function should return the sum.
  • Call the function and pass in the array variable from step 1.
  • Save the results of the step above to a variable named mySum.
  • Console log the variable mySum.

Result

Console:

If your numbers array looks like this: [4, 7, 8008, 11, 9, -1]

Output: 8038

Level 4: Do I Need to Repeat Myself (Advanced Loops and Functions)

Codepen Instructions

Create a new CodePen pen.


Instructions

  • Create an array of words in a sentence that describes you.
  • Create an repeatMyself function that should console.log() rows of words. It should take an array containing the words of a sentence and output them in the developer console.
  • Use this starter code to complete your exercise.
    
    // Create an array that contains the words in the sentence
    var sentenceBio = [];
    
    // The repeatMyself function should accept the array as the sole argument
    function repeatMyself (theWordArray) {
        /*
          Write a `for` loop that iterates over the array argument and
          outputs the words.
         */
    }
    
    // Invoke the function and pass in the array
    repeatMyself(sentenceBio)
            

Results


I 
I spent 
I spent my 
I spent my caterpillar 
I spent my caterpillar days 
I spent my caterpillar days in
I spent my caterpillar days in marketing,
I spent my caterpillar days in marketing, my
I spent my caterpillar days in marketing, my cocoon
I spent my caterpillar days in marketing, my cocoon days
I spent my caterpillar days in marketing, my cocoon days at
I spent my caterpillar days in marketing, my cocoon days at Nashville
I spent my caterpillar days in marketing, my cocoon days at Nashville Software
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, 
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and my
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and my butterfly
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and my butterfly days
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and my butterfly days as 
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and my butterfly days as a 
I spent my caterpillar days in marketing, my cocoon days at Nashville Software School, and my butterfly days as a developer.
    

Level 4: I'm a Bit Overly Excited (Advanced Conditionals and Loops)

Codepen Instructions

Create a new CodePen pen.


Instructions

  • Create an array of words in a sentence that describes you.
  • Create an overlyExcited function that should console.log() rows of words. It should take an array containing the words of a sentence and output them in the developer console.
  • Then add logic to overlyExcited that places an exclamation point (!) after every third word. This will require you to do some basic math in JavaScript, and use an if statement.
  • The technical phrasing of the task ahead: If the current value of the counter variable can be evenly divided by 3 - using the JavaScript remainder operator - then add a single exclamation point (!) to the output.
  • Use this starter code to complete your exercise.
    
    // Create an array that contains the words in the sentence
    var sentenceBio = [];
    
    // The overlyExcited function should accept the array as the sole argument
    function overlyExcited (theWordArray) {
        /*
          Write a `for` loop that iterates over the array argument and
          outputs the words. Use a conditional to add an exclamation point after every third word.
         */
    }
    
    // Invoke the function and pass in the array
    overlyExcited(sentenceBio)
            

Result



I! 
I! spent 
I! spent my 
I! spent my caterpillar! 
I! spent my caterpillar! days 
I! spent my caterpillar! days in
I! spent my caterpillar! days in marketing,!
I! spent my caterpillar! days in marketing,! my
I! spent my caterpillar! days in marketing,! my cocoon
I! spent my caterpillar! days in marketing,! my cocoon days!
I! spent my caterpillar! days in marketing,! my cocoon days! at
I! spent my caterpillar! days in marketing,! my cocoon days! at Nashville
I! spent my caterpillar! days in marketing,! my cocoon days! at Nashville Software!
I! spent my caterpillar! days in marketing,! my cocoon days! at Nashville Software! School, 
I! spent my caterpillar! days in marketing,! my cocoon days! at Nashville Software! School, and
I! spent my caterpillar! days in marketing,! my cocoon days! at Nashville Software! School, and my!
...
    

Bonus Instructions

Add logic in the overlyExcited function to the increase the number of exclamation points after every third word. The number of exclamation points (!) will be determined by how many times the counter variable can be divided by 3.


I! 
I! spent 
I! spent my 
I! spent my caterpillar!! 
I! spent my caterpillar!! days 
I! spent my caterpillar!! days in
I! spent my caterpillar!! days in marketing,!!!
I! spent my caterpillar!! days in marketing,!!! my
I! spent my caterpillar!! days in marketing,!!! my cocoon
I! spent my caterpillar!! days in marketing,!!! my cocoon days!!!!
I! spent my caterpillar!! days in marketing,!!! my cocoon days!!!! at
I! spent my caterpillar!! days in marketing,!!! my cocoon days!!!! at Nashville
I! spent my caterpillar!! days in marketing,!!! my cocoon days!!!! at Nashville Software!!!!!
I! spent my caterpillar!! days in marketing,!!! my cocoon days!!!! at Nashville Software!!!!! School, 
I! spent my caterpillar!! days in marketing,!!! my cocoon days!!!! at Nashville Software!!!!! School, and
...