DEV Community

Zero Hour
Zero Hour

Posted on

What wrong with this codes?

It doesn't output. What's the functional fix to it?

const discountFunc = () => {
    let productPrice = 1000;
    let discountCode = ABCD;
    if (productPrice == 1000 && discountCode == ABCD) {
            return document.getElementById("checkOut").innerHTML = productPrice / 2;
        } else {
            return document.getElementById("checkOut").innerHTML = productPrice;
        }
}
Enter fullscreen mode Exit fullscreen mode
<section>
                <button onclick="discountFunc()">Get discount</button>
                <p id="checkOut"></p>
            </section>
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
citronbrick profile image
CitronBrick • Edited

onclick accepts a function reference & not a value, hence parantheses should not be added to the end of discountFunc.

"ABCD" is most probably a String & hence needs double quotes around it.

Collapse
 
zerohour profile image
Zero Hour

Not making the value ABCD a string is a mistake but fundamentally, the code is not functional. I put it into a sting but it still does not work.