gpt4 book ai didi

JavaScript 转换器价格未定义

转载 作者:行者123 更新时间:2023-11-28 09:53:57 25 4
gpt4 key购买 nike

我在完成此 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>

最佳答案

这是删除所有错误后的 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);

关于JavaScript 转换器价格未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10425325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com