Skip to content

Instantly share code, notes, and snippets.

@jack-guy
Created March 10, 2019 03:13
Show Gist options
  • Save jack-guy/2099d643b77ba472570425a55a17c531 to your computer and use it in GitHub Desktop.
Save jack-guy/2099d643b77ba472570425a55a17c531 to your computer and use it in GitHub Desktop.
function getIceCreamFlavorToPrice(flavors, prices) {
let iceCreamFlavorToPrice;
for (let i = 0; i < flavors.length; i++) {
iceCreamFlavorToPrice[flavors[i]] = prices[i];
}
return iceCreamFlavorToPrice;
}
let iceCreamFlavors = ['vanilla', 'chocolate', 'strawberry'];
let iceCreamPrices = ['$5.50', '$5.75', '$6.00'];
let iceCreamFlavorToPrice = getIceCreamFlavorToPrice(iceCreamFlavors, iceCreamPrices);
formEl.addEventListener('submit', (formData) => {
iceCreamFlavors.push(formData.flavor);
iceCreamPrices.push(formData.price);
iceCreamFlavorToPrice = getIceCreamFlavorToPrice(iceCreamFlavors, iceCreamPrices);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment