Ad
  • Custom User Avatar

    Actually, the x is defined at the top of the function. The word "var" just so happens to be inside the loop. Javascript defines ALL variables at the top of a function.

  • Custom User Avatar

    You are defining x within the loop and then trying to reference it outside of the loop. Also I am not sure why you are calling parseInt or returning -1 when x is falsy (what if x is zero? isnt that a correct value?).