I've used Google's material icons in a navbar and used the following javascript to switch between div's when the icons are clicked. But, for some reason, when I first go into the webpage, all the div's are showing, instead of only the one that is currently being viewed. The javascript switching is working, but I don't know why at first everything shows. Is it because I need to change their display to none? To view it all go to https://tafc.glitch.me/content.html
var page = document.getElementsByClassName("page");
function switchTo(index) {
  for (var i = 0; i < page.length; i++) {
    page[i].style.display = "none";
  }
  page[index - 1].style.display = "block";
  window.scroll(0, 0);
}
switchTo(1);* {
  margin: 0;
  padding: 0;
  text-decoration: none;
}
@keyframes slidein {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0%);
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
body {
  background-color: darkcyan;
}
nav header {
  background: linear-gradient(45deg, rgb(255, 17, 0), rgb(255, 200, 5));
  padding: 11px;
  height: 44px;
}
nav header a {
  text-decoration: none;
  color: midnightblue;
  font-size: 33px;
  margin: 5.5%;
}
.title {
  color: firebrick;
  font-family: serif;
  font-style: normal;
  font-weight: bold;
  font-size: 75px;
  font-variant: small-caps;
  line-height: 105%;
  padding-left: 12.5px;
  animation: slidein 2s;
}
h2 {
  color: gold;
  font-family: serif;
  font-style: normal;
  font-size: 30px;
  font-variant: small-caps;
  padding-left: 12.5px;
  animation: slidein 2s;
}
img {
  display: block;
  float: right;
  width: 30%;
  height: 30%;
  padding-right: 12.5px;
}
.page {
  animation: fade 2s;
}<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link
      rel="icon"
      href="https://cdn.glitch.com/8a4e3a34-26d3-443f-8e6c-ea2607c91f8c%2FAvatar%20on%20ice-32.png?v=1628529343716"
    />
    <title>The TAFC Website</title>
    <script src="/script.js"></script>
    <link rel="stylesheet" href="/style.css" />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/icon?family=Material+Icons"
    />
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,800;1,500&display=swap"
    />
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/css2?family=Lato&display=swap"
    />
  </head>
  <body>
    <nav>
      <header>
        <a href="javascript:switchTo(1);"><i class="material-icons">home</i></a>
        <a href="javascript:switchTo(2);"
          ><i class="material-icons">local_fire_department</i></a
        >
        <a href="javascript:switchTo(3);"><i class="material-icons">air</i></a>
        <a href="javascript:switchTo(4);"
          ><i class="material-icons">water</i></a
        >
        <a href="javascript:switchTo(5);"
          ><i class="material-icons">terrain</i></a
        >
        <a href="javascript:switchTo(6);"
          ><i class="material-icons">shopping_cart</i></a
        >
        <a href="javascript:switchTo(7);"><i class="material-icons">info</i></a>
        <a href="javascript:switchTo(8);"
          ><i class="material-icons">copyright</i></a
        >
      </header>
    </nav>
    <div class="page">
      <h1 class="title">
        The TAFC Website
      </h1>
      <h2>
        Welcome to the Homepage of the Team Avatar Fan Club!
      </h2>
      <img
        src="https://cdn.glitch.com/8a4e3a34-26d3-443f-8e6c-ea2607c91f8c%2FIMG_1854.PNG?v=1628338275471"
        alt="Avatar the Last Airbender and The Legend of Korra element symbols."
      />
    </div>
    <div class="page">
      <h1 class="title">
        The Element of Fire
      </h1>
    </div>
    <div class="page">
      <h1 class="title">
        The Element of Air
      </h1>
    </div>
    <div class="page">
      <h1 class="title">
        The Element of Water
      </h1>
    </div>
    <div class="page">
      <h1 class="title">
        The Element of Earth
      </h1>
    </div>
    <div class="page">
      <h1 class="title">
        Merchandise Shop
      </h1>
    </div>
    <div class="page">
      <h1 class="title">
        About TAFC
      </h1>
    </div>
    <div class="page">
      <h1 class="title">
        Copyright Information
      </h1>
    </div>
  </body>
</html> 
    