I got a script in which if you click on an apple, grape, or banana, it will alert you the price, with the tax from the state that you selected. But, for some reason I keep on getting NaN. It started coming NaN when I added the script that gets the percent from the number.
var apple = 2
var bananna = 3
var grapes = 4
var NJ = 6.625
var NY = 8.225
var PA = 6
var FL = 8
var e = document.getElementById("state").value
var oi;
if (e == NJ) {
oi = NJ
} else if (e == NY) {
oi == NY
} else if (e == PA) {
oi == PA
} else {
oi == FL
}
function myFunction() {
var percent = (oi / 100) * grapes;
alert(percent)
}
function yFunction() {
var percent = (oi / 100) * apple;
alert(percent)
}
function mFunction() {
var percent = (oi / 100) * bananna;
alert(percent)
}
<h2>Enter state of residence.</h2>
<select name="state" class="state" id="state">
<option value="NJ">NJ</option>
<option value="NY">NY</option>
<option value="PA">PA</option>
<option value="FL">FL</option>
</select>
<h2> Click on what you wish to buy.</h2>
<button type="button" id="i"> <img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" onclick = "yFunction()" height ="80" width="100" /></button>
<button type="button" id="o"> <img src="https://th-thumbnailer.cdn-si-edu.com/xK6NAJHiv_51fzn5sDiQt0eD5Is=/fit-in/1600x0/https://tf-cmsv2-smithsonianmag-media.s3.amazonaws.com/filer/d5/24/d5243019-e0fc-4b3c-8cdb-48e22f38bff2/istock-183380744.jpg" onclick = "mFunction()" height ="80" width="100" /></button>
<button type="button" id="h"> <img src="https://www.meijer.com/content/dam/meijer/product/0000/00/0004/02/0000000004022_2_A1C1_1200.png" onclick = "myFunction()" height ="80" width="100" /></button><br>