I am working on a document and I am trying to find the height of the page on different screen sizes. For example In the code below I am trying to make a button that when clicked takes you back to the top of the page, when you get to the bottom of the page it appears and when you get past a certain height it disappears. Can anyone help please.
window.addEventListener("scroll", scrollFunction);
            function scrollFunction() {
                if (window.pageYOffset > 300) {
                    backToTop.classList.toggle("show");
                }
            }.back-to-top {
    width: 40px;
    height: 40px;
    background-color: green;
    position: fixed;
    bottom: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: 0 0 8px 3px darkgrey;
    cursor: pointer;
    opacity: 0;
    transform: scale(0, 0);
    transition: opacity 250ms ease-in, transform 250ms ease-in;
}
.show {
    opacity: 1;
    transform: scale(1, 1);
}<div class="top-container">
                <div class="back-to-top">
                    <i class="fas fa-arrow-up"></i>
                </div>
            </div> 
    