My cash variable in javascript shows up as {} on my console.log(cash) call. I have tried calling it inside and outside of my click event but it does not change the outcome. It seems that there is a disconnect between my HTML and javascript, although I am unable to pinpoint where the disconnect is. Any hints would be much appreciated. My code is far from finished, so I’m sorry for the cut off at the else statement.
Hello~ I haven’t reached the assignment yet so take this with a bucket of salt.
When you console.log(cash), it’s only logging the variable cash that references the id “cash” from html. Cash is also just a reference to the element, not the value.
You might find that logging cashValue does nothing. That’s because the text box is empty and console log runs from the start. (There’s nothing in the text box when console log ran.)
Try making a function that gets the value when it is called. (For example, making a variable that references .value again) Console log the update within the function.
button.addEventListener("click", fungi);
const fungi=()=>{
let mushroom=textBox.value
console.log(mushroom)
}
Thank you for your reply, your example made me learn a few things about finding where things were going wrong. I now see the value pop-up in my console but I had to change something: I used a query selector instead of getElementById. Im not sure why this changes thing but there is a new issue: for some reason, it is not detecting when the input box has no value. I tried .value and without, and the response is the same. However, when I change any of the code and the preview reloads, the alert pops up? Even though its inside a click event. How is the click event being used if I am not using the button? Thank you again for your help and insight.
I now see the value pop-up in my console but I had to change something: I used a query selector instead of getElementById. I’m not sure why this changes things but there is a new issue: for some reason, it is not detecting when the input box has no value. I tried .value and without, and the response is the same. However, when I change any of the code and the preview reloads, the alert pops up? Even though its inside a click event. How is the click event being used if I am not using the button? Thank you again for your help and insight.
it is not detecting when the input box has no value. I tried .value and without, and the response is the same. However, when I change any of the code and the preview reloads, the alert pops up
I’m not seeing the same. When trying the code, the alert only pops up when clicking with an empty text field. Nothing is logged until clicking the button.
It is however, logging an empty array for when there is an input without .value on cashInput.
I updated ivalue = cashInput to be ivalue = cashInput.value and it shows on my end the same as before. Everything seems to be working now, and the box now properly shows the alert after clicking a button instead of upon refreshing the preview. I really appreciate your help, I will let you know if I stumble upon any other issues. Thank you very much!