How do you program this Javascript file for allowing more than one denominations to be inserted into a vending machine?

  javascript

I am working on a school assignment where I must have the code to allow more than one denomation inserted into the vending machine and checks if you can buy four soda products? Here is the Javascript code.

function vendingFunction() {
  console.log('Testing. 1. 2. 3. All clear!');

  var $money = "";
  var codeSequence = ["A1", "A2", "B1", "B2"];
  var $soda = ["Coca-Cola", "Fanta", "Sprite", "Schweppes"];
  const coinValue = ["0.50", "1.00"];
  const sodaPrice = ["0.55", "0.95", "1.05", "0.90"];

  var sodaChoice = window.prompt("Select your code.");
  console.log(sodaChoice);

  if (sodaChoice == "A1") {
    window.alert("You selected Coca-Cola.");
    window.alert("This costs $" + sodaPrice[0] + "."); //sodaprice[0] calls the first element in "sodaPrice's" array
    console.log(sodaPrice[0]);
  }

  if (sodaChoice == "A2") {
    window.alert("You selected Fanta.");
    window.alert("This costs $" + sodaPrice[1] + ".");
    console.log(sodaPrice[1]);
  }

  if (sodaChoice == "B1") {
    window.alert("You selected Sprite.");
    window.alert("This costs $" + sodaPrice[2] + ".");
    console.log(sodaPrice[2]);
  }

  if (sodaChoice == "B2") {
    window.alert("You selected Schweppes");
    window.alert("This costs $" + sodaPrice[3] + ".");
    console.log(sodaPrice[3]);
  }
}

Source: Ask Javascript Questions

LEAVE A COMMENT