Skip to content
Advertisement

What am doing wrong in here?

Input value always gets into if condition first even am parsing it to parseInt() and when page refreshed with a number it gets into else condition, like its not registering the inputValue at first place, also if i add a submit event rather an click one event doesnt fires up.

JavaScript

Advertisement

Answer

You’re recording the value of the input on page load, so at first it is empty.

Move this line

JavaScript

to be the first line of your function that runs after clicking your button.

JavaScript

Also it is probably best to use ID’s for those elements and select them by their ID’s rather than a class. ID’s are unique so there can only be one of them on the page.

I also corrected typos in those lines, missing ” and misspelled function.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement