Skip to content

Instantly share code, notes, and snippets.

@appoll
Created February 21, 2022 18:42
Show Gist options
  • Save appoll/515f937b7b4acf499fa6977d23e0976c to your computer and use it in GitHub Desktop.
Save appoll/515f937b7b4acf499fa6977d23e0976c to your computer and use it in GitHub Desktop.
ages = [12, 16, 24, 98, 64, 24, 98, 64, 24, 98, 64]
// Print all the ages in your array :)
// We use the for loop
for (i = 0; i < ages.length; i = i + 1){
currentAge = ages[i];
console.log("Position is: " + i);
console.log("Value is: " + currentAge);
}
// E0. Print all the ages in the array in reverse order;
// for (let i = 0; i < ages.length; i = i + 1){
// console.log(ages[i]);
// }
// E1. Print all positions of all ages greater than 18;
// for (let i = 0; i < ages.length; i = i + 1){
// console.log(ages[i]);
// }
// E2. Iterate through the array and calculate the sum of its values;
// for (let i = 0; i < ages.length; i = i + 1){
// console.log(ages[i]);
// }
// E3. Break & answer question:
// Is there at least a person over 18 in this group?
// for (let i = 0; i < ages.length; i = i + 1){
// console.log(ages[i]);
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment