0

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>

2
  • 1
    This is not java. In future, please use the correct tags for your questions. Commented Mar 10, 2018 at 4:18
  • Look at your browsers error console (F12 in Chrome). Are there any JavaScript errors? Commented Mar 10, 2018 at 5:56

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

didn't know you can only have 1 body tag (lesson learned). I have the closing html tag, idk why i didn't copy and paste it with the rest of the code. Fixed the string issue and the "===". After running it through several times, it seems that it only works if I include only the code before the location declaration line, and delete the main function from the alert one, leaving only the text.
0

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.

1 Comment

yup, i just noticed it too. Fixed it, but I'm guessing the bigger problem is something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.