gpt4 book ai didi

javascript - 基本 HTML + JavaScript,警报功能不起作用

转载 作者:行者123 更新时间:2023-12-03 02:19:58 25 4
gpt4 key购买 nike

我正在尝试创建一个程序来计算(初始价格折扣+运费)*税。我必须使用警报和提示功能,但我的警报功能似乎不起作用...我尝试过移动它并通常疯狂地复制/粘贴(在代码中很明显),但似乎代码只是不'不要一路跑过去。

<!DOCTYPE html>
<html>

<head>
<!-- My Name -->
<title> HW#6 </title>

</head>

<body>
<h1>The Company Store</h1>
<h2>Processing Screen</h2>
</body>

<body>

<script>

function priceCalc(initialPrice, finalPrice, isMember, location) {
return finalPrice;
}

var initialPrice = parseInt(prompt("Enter price"));
var isMember = prompt("Enter Y if you are a member, N if not");
isMember = isMember.toUpperCase();
var location = prompt("enter NJ if you are from New Jersey, NY if from New York");
location = location.toUpperCase();

if (member = Y) {
var finalPrice = price * 0.9;
}
else {
var finalPrice = price; }


if (location = NJ) {
finalPrice = (finalPrice + 5) * (1 + 0.07);
alert("The final price is" + priceCalc(initialPrice, finalPrice, isMember, location));
}
else if (location = NY) {
finalPrice = (finalPrice + 3) * (1 + 0.08);
alert("The final price is" + priceCalc(initialPrice, finalPrice, isMember, location));
}

alert("The final price is" + priceCalc(initialPrice, finalPrice, isMember, location));


</script>

</body>

最佳答案

我发现一些问题:

  1. 您有 2 <body>标签
  2. 您没有关闭 <html>标签
  3. 当您检查字符串是否相等时,必须用 ' 将字符串括起来。或"
  4. 检查相等性时,必须使用 ===== (严格平等)。
    =用于作业

我建议先回去学习基础知识。

关于javascript - 基本 HTML + JavaScript,警报功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49205237/

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