-1

I have a function called userInput that checks if seconds is equal to x, then it gives an alert to the user, and then resets the time. The userInput does not check if seconds is equal to x. Should I use a for loop? Here's my code:

var userInput = function(x) {
  if (seconds == x) {
    var done = alert("You're done!");
    h1.textContent = "00:00:00"
    seconds = 0; minutes = 0; hours = 0;
  }
}
  userInput(x);

And just so you know this, seconds, minutes, and hours are already declared as variables.

Any help is appreciated, thanks.

  • 1
    See [*How to create a minimal, complete, and verifiable example*](http://stackoverflow.com/help/mcve). You can post a runnable snippet here to display the issue. – RobG Aug 04 '16 at 23:40
  • Where is `seconds` coming from? And, your function takes an argument called `x` but when you call `userInput` you're passing `x`. The `x` in the function is [shadowing](http://stackoverflow.com/questions/11901427/an-example-of-variable-shadowing-in-javascript) the `x` outside the function. – kevin628 Aug 04 '16 at 23:42
  • The previous question was deleted: http://stackoverflow.com/questions/38778172/my-userinput-function-does-not-work. It contained the rest of the code and all the context. – Sebastian Simon Aug 04 '16 at 23:43
  • Ok, kevin628 fixed the issue, I was overshadowing `x`. Thanks for all the help! – sir_smiggles Aug 04 '16 at 23:46
  • `he previous question was deleted` - different user! – Jaromanda X Aug 04 '16 at 23:53

1 Answers1

-1

I was overshadowing x in my code. Thanks for the help in the comments

  • Why is that a problem? You're passing `x` to the function, so it will get the same value as the outer `x`. – Barmar Aug 04 '16 at 23:58
  • A good answer to a question should explain and show how to fix the problem. This answer is not useful to future readers with a similar problem. – Barmar Aug 04 '16 at 23:59