I’m trying to create a scroll button for a website but it’s not working...Any help please?

Any help with this please??
I’m just learning JavaScript and I want to create a scroll button that takes one back to the top of a website after viewing the website till the end.
There’s probably a lot wrong with the code but I don’t even know.
Thanks a lot.

Keeps giving me this error code

Without seeing the actual code (like, in a https://codepen.io/ or a https://repl.it/ ), debugging is simply poking a stick in the dark.

2 Likes

okay, will try doing that now

How about now??

Now that you’ve put it in codepen, are you seeing a red warning in the JS pane? There are errors.

First, you define the var lines in the first two, but that var keyword on the second is causing an error.

Then, later on, you have an if statement. Looks like

      if (docHeight != "undefined") (
      	offset =  docHeight / 4;
      	)

Here’s the issue - if statements are followed by curly braces ({...}), not parentheses ((...)).

Same in the function definition you’re writing for your callback function: use curly braces.

I’m still not getting it sorry. Can you please check it again?

Thank you so much @snowmonkey and @camperextraordinaire, the error message has stopped now but my web console is still saying “contactBtn is null” and the code for the scroll button doesn’t seem to work. Thanks for your inputs so far.

One of the huge advantages of using codePen, it’s really great at putting error messages right out there for you. Click on that red icon in the code editor, it’ll pop an error message right near the error itself. And fixing the error? Removes the message. And usually moves on to the NEXT error.

Bug squashing, serving developers since 1967. :wink:

It’s working fine now, thanks so much @camperextraordinaire and @snowmonkey