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;
}
}
<section>
<button onclick="discountFunc()">Get discount</button>
<p id="checkOut"></p>
</section>
Top comments (2)
onclick
accepts a function reference & not a value, hence parantheses should not be added to the end ofdiscountFunc
."ABCD"
is most probably a String & hence needs double quotes around it.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.