In: Computer Science
var selectedColor =
document.getElementById("colorChoice").value;
var selectedStyle = document.getElementById("style").value;
var selectedSize = document.getElementById("size").value;
var orderMessage = "Your order is: Color = " +
selectedColor
+ "; Style = " + selectedStyle
+ "; Size = " + selectedSize+"\n";
if (selectedStyle==="Long-sleeve")
//Add code to calculate the price and concatenate it to the
orderMessage
//For example, "The order is: Color = gray; Style=T-Shirt; Size =
XL \nThe price is $12"
//If the style and size are not available, then concatenate the
message that it is not available instead of a price.
// -- Notice: the color, style, and style is already stored
variables for you
// a t-shirt in any size is $9
// a long-sleeve t-shirt in adult sizes is $18
// a long-sleeve t-shirt is youth sizes is not available
// a tech shirt is is $12 except 2XL and 3XL which are $16.
alert(orderMessage);
//Next change this alert to write the order status to the HTML
page.
}
var selectedColor =
document.getElementById("colorChoice").value;
var selectedStyle =
document.getElementById("style").value;
var selectedSize =
document.getElementById("size").value;
var orderMessage = "Your order is: Color = " +
selectedColor
+ "; Style = " + selectedStyle
+ "; Size = " + selectedSize+"<br>";
// if selectedStyle is long-sleeve (case insensitive
comparison)
/// toLowerCase method converts the string to lower case so the
comparison can be done without taking case into account
if (selectedStyle.toLowerCase()==="long-sleeve")
{
// if selectedSize is adult (case
insensitive comparison)
if(selectedSize.toLowerCase() ===
"adult")
{
orderMessage +=
"The price is $18.";
}else if(selectedSize.toLowerCase()
=== "youth") // if selectedSize is youth (case insensitive
comparison)
{
orderMessage +=
"It is not available.";
}
}else if(selectedStyle.toLowerCase() === "tech shirt")
// if selectedStyle is tech shirt (case insensitive
comparison)
{
// if selectedSize is 2xl or 3xl
(case insensitive comparison)
if(selectedSize.toLowerCase() ===
"2xl" || selectedSize.toLowerCase() === "3xl")
{
orderMessage +=
"The price is $16.";
}else // any other size for tech
shirt
orderMessage +=
"The price is $12.";
}else if(selectedStyle.toLowerCase() === "t-shirt") //
if selectedStyle is t-shirt (case insensitive comparison)
orderMessage += "The price is
$9.";
else // if any other item then its not
available
orderMessage += "It is not
available.";
//Add code to calculate the price and concatenate it
to the orderMessage
//For example, "The order is: Color = gray;
Style=T-Shirt; Size = XL \nThe price is $12"
//If the style and size are not available, then
concatenate the message that it is not available instead of a
price.
// -- Notice: the color, style, and style is already
stored variables for you
// a t-shirt in any size is $9
// a long-sleeve t-shirt in adult sizes is $18
// a long-sleeve t-shirt is youth sizes is not
available
// a tech shirt is is $12 except 2XL and 3XL which are
$16.
//alert(orderMessage);
//Next change this alert to write the order status to
the HTML page.
//Suppose result is the id of the HTML element where
we need to display the order details
document.getElementById("result").innerHTML =
orderMessage;
}