I'm having a small project where I have to do a shopping list (for fruit salad) which allows user to add products and set prices for them. I've managed to do this so far that the "final" prompt shows all added products and prices for the user. Problem is that it should show all this from lowest to the highest by the price. I've tried to search information about this but haven't found anything relevant. Is there any help for me? Thank you in advance!
var count = 0;
var fruitSaladItems = [];
var ingredient=true;
while (ingredient && count<22) {
count++
ingredient= prompt("Enter the fruit salad ingredients");
if(ingredient){
var price=prompt("Enter the price");
fruitSaladItems.push(ingredient+" €"+price);
}
}
alert(fruitSaladItems.join(','));
Here you can see the edited code:
var count = 0;
var fruitSaladItems = [];
var ingredient=true;
while (ingredient && count<22) {
count++
ingredient = prompt("Enter the fruit salad ingredients");
if (ingredient) {
var price = parseFloat(prompt("Enter the price"));
fruitSaladItems.push({ ingredient, price });
}
}
alert(fruitSaladItems.join(','));