Skip to content

Instantly share code, notes, and snippets.

@outoftime
Last active May 16, 2017 12:57
Show Gist options
  • Select an option

  • Save outoftime/630a2c5cda1f344bad8349f632545685 to your computer and use it in GitHub Desktop.

Select an option

Save outoftime/630a2c5cda1f344bad8349f632545685 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=630a2c5cda1f344bad8349f632545685
<!DOCTYPE html>
<html>
<head>
<title>For Loops with Arrays</title>
</head>
<body>
<div id="musicians"></div>
</body>
</html>
{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.css","editor.html"]}
// 1. Modify the array definition below so that it lists
// FIVE of your favorite musicians.
var musicians = [];
// 2. Now modify the for loop below so that the five musicians in your array
// are printed to the page.
for (var i = 0; i < 5; i = i + 1) {
var musician;
$("#musicians").append("<p>" + musician + "</p>");
}
// 3. Add another musician to the array above. Notice that they are not printed
// out!
//
// You could change the for loop to specifically work with six musicians.
// INSTEAD, modify your for loop so that it will work with ANY length array.
// 4. Currently, the musician names are printed in paragraph tags. Change the
// code in the for loop above so that they are printed in H1 tags instead.
// 5. SPICY CHALLENGE: Change the for loop so that the musician names are
// printed in reverse order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment