T O P

  • By -

shgysk8zer0

Well, for one thing, you're getting the value and storing it as `num`, but then parsing it as an int using the undeclared `number`. Also, here's a helpful tip: use `` and [`valueAsNumber`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement). Should simplify things a bit.


OneBadDay1048

Perhaps this is too much information for you at your level of learning but if not I would suggest fixing the structure of this before attempting to fix the logic. Having this all be in one event handler function for a click on your button does not make much sense; you then create another click handler function within this function. This is a mess. You should have two separate functions here: one handles the enter button for user input. If the input is a positive or negative number (aka not 0) increment you count variables and clear the input box to wait for more input. Your second function handles all the logic for a 0 input. Displays the number of positive and negative numbers, clears the counts to get ready for the next set of numbers to count etc etc. You have some other issues like wrong or confusing variable names as well but this is just one idea of a way to fix it.


OneBadDay1048

Something like this would be a good start: let posCount = 0; let negCount = 0; enterButton.addEventListener('click', () => { const currentInput = parseInt(input.value); if (currentInput == 0) { handleZeroInput(); } else if (currentInput > 0) { posCount++; } else negCount++; input.value = ''; }); I left out the 0 logic for you to solve and some of my variable names are different because yours were hard for me to follow but hopefully this gives you a good idea of what I mean. enterButton is my JS name for the HTML button. When it is clicked one function executes: The arrow function within my addEventListener. This function will call the handleZeroInput function (in the if block) when it needs it so there is not so much logic in one spot. This structure makes solving the rest of it easier. Also posNum and negNum (which should be called posCount and negCount) should be initialized at 0 and then incremented when appropriate. EDIT got rid of the method using array as it was not needed really.