You're going to get familiar with iterating through arrays in Javascript.
There are four functions to complete in this lab:
- Dwarf Roll Call
- Summon Captain Planet
- Long Planeteer Calls
- Find the Cheese
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 "
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.
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.
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.