When it comes to my JavaScript function designed to inquire about the number of products a user wants to order, I'm facing some issues. The function should display a message if the user tries to order less than one product and show an alert saying "Ordering (quantity) (product)[s]". Unfortunately, these features aren't working as intended.
I attempted to fix this by implementing a return for the quantity, but all it did was alter the webpage to display the quantity number. However, it did prove that the quantity functionality is functional.
function promptQuantity(product) {
var quantity = prompt("How many " + product + "s would you like?");
if (quantity > 1) {
var plural = "s";
}
if (quantity = 1) {
var plural = "";
}
if (quantity < 1) {
alert("Don't be ridiculous! You can't order less than one " + product + "!");
}
if (quantity > 0) {
alert("Ordering " + quantity + " " + product, plural);
}
}
My expectation from this function is to send an alert notifying the user about their order quantity of the product, but unfortunately, it only returns as "Ordering 1 (product)".