The problem

You are building 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.

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",
        "price": 0.75,
        "sugarFree": false,
        "energy": false,
        "quantity": 12
    },
    {
        "name": "Coke",
        "price": 0.75,
        "sugarFree": false,
        "energy": false,
        "quantity": 12
    },
    {
        "name": "NOS",
        "price": 2.00,
        "sugarFree": false,
        "energy": true,
        "quantity": 24
    },
    {
        "name": "Diet Pepsi",
        "price": 0.75,
        "sugarFree": true,
        "energy": false,
        "quantity": 12
    }
]

Attribute List

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

Expected Output

name: Pepsi, price: 0.75
name: Coke, price: 0.75
name: NOS, price: 2
name: Diet Pepsi, price: 0.75

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