Zhen
Zhen

Reputation: 1

Basic HTML + JavaScript, alert function not working

I'm trying to create a program to calculate (initial price-discount+shipping)*tax. I have to use alert and prompt function, but my alert function doesn't seem to work...I've tried moving it and generally copy/pasting frantically (evident in the code), but it seems that the code just doesn't run all the way through.

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

Upvotes: 0

Views: 52

Answers (2)

Pustur
Pustur

Reputation: 177

I see a few problems:

  1. You have 2 <body> tags
  2. You didn't close the <html> tag
  3. When you check equality with a string you must enclose the string with ' or "
  4. When you check equality you must use == or === (strict equality).
    = is used for assignments

I'd suggest to go back and learn the basics first.

Upvotes: 1

kshetline
kshetline

Reputation: 13682

That needs to be location === 'NJ' and location === 'NY'.

I don't know if that's all that's wrong, but you need to fix that to start.

Upvotes: 0

Related Questions