What is missing from my discount code to make this work? Am I missing a variable?

I thought I had everything correct and I still can’t seem to figure out why the function isn’t working out the way it is supposed to. I have this issue where the code is having a reference error but I’m not sure how to define the function. I also put it through the W3 validator but that’s not telling me anything.

<html lang="en-us">
<meta charset="utf-8">
<title>discount amount</title>


        /* Input: purchase amount
         * Processing: determine through if statements if they get a 
         * Output: final price after tax
        // Computes and returns a discounted purchase amount.
        function getDiscountedAmount(purchase) {
         var purchase = 
            var dayOfWeek = new Date().getDay();
            var output = document.querySelector("#output");
            let rate;
            if (purchase < 50) {
                rate = 0.06;
            else if (purchase < 100 && [2, 3].includes(dayOfWeek)) {
                rate = 0.06;
            else if (purchase < 500 && [2, 3].includes(dayOfWeek)) {
                rate = 0.06;
            let discount = purchase * rate;
            return purchase - discount;
            output.innerHTML = "$" + String(getDiscountedAmount(200));
Please enter your final price: <input type="text" id="purchase" size="5"> 
<button type="button" onclick="getDiscountedAmount(purchase)">discount? 
<div id="output"></div>  

83 thoughts on “What is missing from my discount code to make this work? Am I missing a variable?”

Leave a Comment