我无法完成此javascript转换咖啡价格..
<html>
<head>
<title>Coffee House</title>
</head>
<body>
<script type="text/javascript">
var drink, ounces, price;
prompt ( "Enter the drink type: espresso, latte, cappuccino, americano" );
prompt ( "Enter the oz: 8, 12, 16" )
var shots = prompt ( "Enter the number of shots" )
if ( drink == "espresso")
price = 1.40;
if (( drink == "latte") || (drink == "cappuccino" ))
{
if ( ounce == 8 )
price = 1.95;
else if ( ounce == 12 )
price = 2.35;
else if ( ounce == 16 )
price = 2.75;
}
if ( drink == "americano" )
price = 1.20 + ( ( (ounce -8)/8 ) * .30 );
price = price + ( (shots) * .50 );
price = "price" * 1.055;
price = Math.round( price * 100 )/100;
alert( "Your " + ounce + "oz. " + drink + "with " + shots + "shots of espresso costs: $ " +price );
</script>
</body>
</html>
答案 0 :(得分:0)
这是删除所有错误后的JavaScript:
var drink, ounces, price;
drink = prompt("Enter the drink type: espresso, latte, cappuccino, americano");
ounces = parseInt(prompt("Enter the oz: 8, 12, 16"));
var shots = parseFloat(prompt("Enter the number of shots"));
if (drink === "espresso") price = 1.40;
if ((drink === "latte") || (drink === "cappuccino")) {
if (ounces === 8) price = 1.95;
else if (ounces === 12) price = 2.35;
else if (ounces === 16) price = 2.75;
}
if (drink === "americano") price = 1.20 + ((ounces - 8) / 8) * 0.30;
price = price + shots * 0.50;
price = price * 1.055;
price = Math.round(price * 100) / 100;
alert("Your " + ounces + "oz. " + drink + "with " + shots + "shots of espresso costs: $ " + price);