Skip to content

Instantly share code, notes, and snippets.

@natafaye
Last active May 10, 2021 23:48
Show Gist options
  • Save natafaye/9583f157518827c4e653c2748094d734 to your computer and use it in GitHub Desktop.
Save natafaye/9583f157518827c4e653c2748094d734 to your computer and use it in GitHub Desktop.
function fillBasket() {
emptyBasket();
// Replace NUMBER_OF_TIMES with how many times you want your loop to loop
for(let i = 0; i < NUMBER_OF_TIMES; i++) {
// The code to run over and over again
}
}
function fillBasket() {
emptyBasket();
for(let i = 0; i < numFish; i++) {
addItemToBasket("fish");
}
}
function fillBasket() {
emptyBasket();
// THE TWO FOR LOOPS WOULD BE HERE
// Replace ARRAY with some array that you want to loop over
// You can also rename your variable from item to something more descriptive
for(const item of ARRAY) {
// The code to run for each item in the array, saved in the variable item
}
}
function fillBasket() {
emptyBasket();
// THE TWO FOR LOOPS WOULD BE HERE
for(const item of otherItems) {
addItemToBasket(item);
}
}
// Replace ARRAY with some array that you want to loop over
// You can also rename your variable from item to something more descriptive
for(const item of ARRAY) {
// The code to run for each item in the array, saved in the variable item
}
// It might look something like this
let friendsAtDoor = ["Jose", "Emily", "Andre", "Simone"];
for(const friend of friendsAtDoor) {
// The variable friend now holds whichever name we're currently working with
// The first time this loop runs, friend will equal "Jose"
// The second time friend = "Emily", etc
alert("Welcome " + friend + "!");
}
// Replace NUMBER_OF_TIMES with how many times you want your loop to loop
for(let i = 0; i < NUMBER_OF_TIMES; i++) {
// The code to run over and over again
}
// You could put a number there
for(let i = 0; i < 5; i++) {
console.log("Let's do this 5 times!");
}
// Or a variable that holds a number
let friendsAtDoor = 5;
for(let i = 0; i < friendsAtDoor; i++) {
alert("Welcome!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment