The problem

You are writing the display engine for a modern fountain soda machine. The machine has attributes for each product defined by the sodas data structure. The machine needs to display the selected list of attributes so the customer can make a choice. The attributes to be displayed are defined by the attributeList array. Write code that iterates over sodas and outputs the attributes and their values.

If possible, write the code to handle both iterations without having to modify the code. It should only be necessary to substitute the attributes to be printed.

Ground Rules:
You are allowed copy/paste the code from the question into your development environment.
You may use the Savvy Coders curriculum, MDN or any code you have previously written as resources to solve the problem.


List of sodas

const sodas = [
    {
        "name": "Pepsi",
        "sugarFree": false,
        "energy": false,
        "image": "fake.cdn/pepsi.jpg"
    },
    {
        "name": "Coke",
        "sugarFree": false,
        "energy": false,
        "image": "fake.cdn/coke.jpg"
    },
    {
        "name": "NOS",
        "sugarFree": false,
        "energy": true,
        "image": "fake.cdn/nos.jpg"
    },
    {
        "name": "Diet Pepsi",
        "sugarFree": true,
        "energy": false,
        "image": "fake.cdn/diet_pepsi.jpg"
    }
]

Attribute List

let attributeList = [
    "name",
    "image"
]

Expected Output

name: Pepsi, image: fake.cdn/pepsi.jpg
name: Coke, image: fake.cdn/coke.jpg
name: NOS, image: fake.cdn/nos.jpg
name: Diet Pepsi, image: fake.cdn/diet_pepsi.jpg

Second Iteration


Attribute List

let attributeList = [
    "name",
    "sugarFree",
    "energy"
]

Expected Output

name: Pepsi, sugarFree: false, energy: false
name: Coke, sugarFree: false, energy: false
name: NOS, sugarFree: false, energy: true
name: Diet Pepsi, sugarFree: true, energy: false