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

时间:2018-03-10 04:08:59

标签: 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>

2 个答案:

答案 0 :(得分:1)

我看到一些问题:

  1. 您有2个<body>代码
  2. 您未关闭<html>代码
  3. 检查字符串是否相等时,必须用'"
  4. 括起字符串
  5. 检查平等时,必须使用=====(严格平等) =用于分配
  6. 我建议先回去学习基础知识。

答案 1 :(得分:0)

需要location === 'NJ'location === 'NY'

我不知道这是否都是错的,但你需要解决这个问题才能开始。