learn-co-students / hs-js-cartoon-collections-js-cartoon-collections-000

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Objectives

You're going to get familiar with iterating through arrays in Javascript.

Instructions

There are four functions to complete in this lab:

  1. Dwarf Roll Call
  2. Summon Captain Planet
  3. Long Planeteer Calls
  4. Find the Cheese

Function 1 - Dwarf Roll Call

dwarves

This function should accept an array of dwarf names, for instance:

["Doc", "Dopey", "Bashful", "Grumpy"]

It should then return a string with the numbered dwarves. The string should look like this:

"1. Doc 2. Dopey 3. Bashful 4. Grumpy "

Function 2 - Summon Captain Planet

captain-planet

This function should accept an array of planeteer calls, like this:

planeteerCalls = ["earth", "wind", "fire", "water", "heart"]

It should then convert each element to uppercase and add an exclamation point at the end. The return value of this method should be an array, in this example:

summonCaptainPlanet(planeteerCalls)
#=> ["EARTH!", "WIND!", "FIRE!", "WATER!", "HEART!"]

Once the test for this method is passing, move on to the next method, long planeteer calls.

Function 3 - Long Planeteer Calls

The longPlaneteerCalls method should accept an array of calls. The function should tell us if any of the calls are longer than four characters. For example:

shortWords = ["wind", "fire"]
longPlaneteerCalls(short_words)
#=> false

assortedWords = ["earth", "wind", "heart", "fire"]
longPlaneteerCalls(assorted_words)
#=> true

Notice the return value of this method is either false or true, depending on the array it was given as an argument.

Once the test for this method is passing, move on to the last function.

Method 4 - Find the Cheese

dancing-mice

The "findTheCheese" function should accept an array of strings. It should then look through these strings and return the first string that is a type of cheese. The types of cheese that appear are cheddar, gouda, and camembert.

For example:

snacks = ["crackers", "gouda", "thyme"]
findTheCheese(snacks)
#=> "gouda"

soup = ["tomato soup", "cheddar", "oyster crackers", "gouda"]
findTheCheese(soup)
#=> "cheddar"

If, sadly, a list of ingredients does not include cheese, return "no cheese!":

ingredients = ["garlic", "rosemary", "bread"]
findTheCheese(ingredients)
#=> null

You can assume that all strings will be lower-case.

View Objectives on Learn.co and start learning to code for free.

About

License:Other


Languages

Language:JavaScript 71.7%Language:HTML 19.2%Language:Shell 9.1%