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

标签 javascript html

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

<!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/

相关文章:

jquery - 在页面加载时禁用透明 div 并希望在页面加载后显示

javascript - Mustache 正在用空字符串替换我的标签

javascript - "Menu"到 "Close"文本转换

javascript - 如何在 javascript 中运行系统命令?

javascript - 钩子(Hook) (`sails-eslint` ) 加载失败

php - jquery .load 重命名表单

javascript - 如何像按钮一样使用 DAT.Gui 调用函数?

javascript - ES6 类多重继承

javascript - jQuery Blur() 不适用于 click() 函数

javascript - 在非 anchor 元素上渲染推文按钮