Module 7 Participation | Looping Examples

Before you go any farther -- open you console -- "shift-ctrl-i"

        // Array Example 1
        const fruits = ['Apple', 'Banana', 'Orange', 'Grapes', 'Mango'];

        for (let i = 0; i < fruits.length; i++) {
            console.log(fruits[i]);
        }
    
        // Array Example 2
        const colors = ['Red', 'Green', 'Blue', 'Yellow', 'Purple'];

        colors.forEach(color => {
            console.log(color);
        });
    
        // Array Example 3
        const numbers = [1, 2, 3, 4, 5];

        let sum = 0;
        for (const number of numbers) {
            sum += number;
        }
        console.log('Sum:', sum);
    
        // Array Example 4
        const countries = ['USA', 'Canada', 'UK', 'Australia', 'Germany'];

        for (const country of countries) {
            console.log(country.toUpperCase());
        }
    
        // Array Example 5
        const animals = ['Dog', 'Cat', 'Elephant', 'Lion', 'Monkey'];

        let output = '';
        animals.forEach(animal => {
            output += animal + ' ';
        });
        console.log(output.trim());