Skip to content

Instantly share code, notes, and snippets.

@appoll
Created November 21, 2022 18:38
Show Gist options
  • Save appoll/10d866b7f8653440b50dc57eaca714f8 to your computer and use it in GitHub Desktop.
Save appoll/10d866b7f8653440b50dc57eaca714f8 to your computer and use it in GitHub Desktop.
ages = [12, 16, 24, 98]
// 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. Count how many ages in the array are greater than 18;
// Hint: an extra variable
for (let i = 0; i < ages.length; i = i + 1){
console.log(ages[i]);
}
// E3. Iterate through the array and calculate the sum of its values;
// Hint: an extra variable
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