Js Beatles Loops Lab

Objectives

  • Build a for loop
  • Build a while loop
  • Build a do-while loop

Instructions

Make sure you run the tests with learn.

  1. Create a function theBeatlesPlay, which accepts two parameters--an array of musicians and an array of instruments.
  2. Create a variable with an empty array.
  3. Use a for loop, which iterates over the array. of musicians. Be careful about what value you set your counter variable to store. (Hint: Think about what the first index of an array is).
  4. The first time through the loop, it should create a string using the first index of the musicians array and the first index of the instruments array: "John Lennon plays guitar".
  5. Add this string to the empty array you created. The loop should make the same sentence for every member of the musicians array.
  6. The function should return the array of new strings containing what instruments each musician plays.

  7. Create a function johnLennonFacts.

  8. This function will accept one argument, an array of facts about John Lennon (note that it might not be exactly the following facts):

const facts = [
  "He was the last Beatle to learn to drive",
  "He was never a vegetarian",
  "He was a choir boy and boy scout",
  "He hated the sound of his own voice"
];
  • Use a while loop to loop over the facts array and add "!!!" to the end of every fact.
  • Return an array of strings with exclamation points.
  1. Create a function iLoveTheBeatles which accepts a number as a parameter.
  2. The function should create a variable that stores an empty array.
  3. Implement a do-while loop inside the function that adds "I love the Beatles!" to the empty array.
  4. The loop should then increment the number passed in as a parameter. The condition of the loop should check to see that the parameter number is less than 15. It should contain a number of strings that represents the difference between the input number and 15.
  5. Return the array with the strings "I love the Beatles!".

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

Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us