-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingredients.js
21 lines (19 loc) · 859 Bytes
/
ingredients.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const ingredients = ["eggs", "milk", "flour", "sugar", "baking soda", "baking powder", "chocolate chips", "bananas"];
// Write a while loop that prints out the contents of ingredients:
let i = 0;
while(i < ingredients.length) {
console.log(ingredients[i]);
i++;
}
// Write a for loop that prints out the contents of ingredients:
for(let i = 0; i < ingredients.length; i++) {
console.log(ingredients[i]);
}
// Write any loop (while or for) that prints out the contents of ingredients backwards:
const reversedIngredients = [];
for(let i = ingredients.length - 1; i >= 0; i--) {
let reverse = ingredients[i];
reversedIngredients.push(reverse);
}
console.log(reversedIngredients);
//index = array.length - 1 aka the last index of ingredients then we stop at 0 decreasing each loop another option is > ingredients.reverse(); console.log(ingredients);