我正在尝试创建一个程序来计算(初始价格折扣+运费)*税。我必须使用警报和提示功能,但我的警报功能似乎不起作用...我尝试过移动它并通常疯狂地复制/粘贴(在代码中很明显),但似乎代码只是不'不要一路跑过去。
<!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>
最佳答案
我发现一些问题:
- 您有 2
<body>
标签 - 您没有关闭
<html>
标签 - 当您检查字符串是否相等时,必须用
'
将字符串括起来。或"
- 检查相等性时,必须使用
==
或===
(严格平等)。
=
用于作业
我建议先回去学习基础知识。
关于javascript - 基本 HTML + JavaScript,警报功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49205237/