Hi,
I used this:
alert(“Hi, welcome to the shop”);
var Bread = 2;
var Milk = 1.5;
var Cheese = 4;
var Yoghurt = 1.2;
var a = (prompt(“How much bread do you want?”));
var b = (prompt(“How much milk do you want?”));
var c = (prompt(“How much cheese do you want?”));
var d = (prompt(“How much yoghurt do you want?”));
console.log(“The total amount to pay is $”,+ (aBread)+(bMilk)+(cCheese)+(dYoghurt));
Which works, however, Ivan put this:
varbread =2;
varmilk =1.5;
varcheese =4;
varyogurt =1.2;
varsum =0;
alert("Hi! Welcome to the Ivan on Tech Shop!");
varinput = prompt("How much bread do you want?");
sum += input * bread;
varinput = prompt("How much milk (liter) do you want?");
sum += input * milk;varinput = prompt("How much cheese do you want");
sum += input * cheese;
varinput = prompt("How many yogurts do you want?");
sum += input * yogurt;
console.log("The total amount to pay is", sum);
Is there a difference or efficiency between either approach, i.e would mine build up more technical debt by creating additional variables in the memory? This is one of the reasons I believe mine is less efficient, perhaps!
Thanks, just wondering as it works anyway