Q:

Javascript events Listeners menu overlay

I am trying to use simple Javascript with no jQuery involve.
I am having a bit of difficulty toggling open and close menu in overlay.
I can open, close, open but will not execute evenListener.
Anyone have a small tip?
Code in CodePen
function toggleMenu() {
  this.classList.toggle('active', true); 
  openOverlay();
}

 function openOverlay() {
   document.getElementById('overlay').style.height = "100%"; 
   x.addEventListener('click', closeOverlay, false);
}
function closeOverlay() {
  this.classList.toggle('active', false);
  document.getElementById('overlay').style.height = "0"; 

  x.addEventListener('click', openOverlay, false);
}

var x = document.getElementById('menu-toggle');
x.addEventListener('click', toggleMenu, false);

A:

classList.toggle returns a bool, so you can simple check if the active class was added or removed.

toggle ( String [, force] )
When only one argument is present: Toggle class value; i.e., if class exists then remove it and return false, if not, then add it and return true...

var overlay = document.getElementById('overlay')
var x = document.getElementById('menu-toggle');

function toggleMenu(e) {
  var isActive = this.classList.toggle('active');
  (isActive) ? overlay.style.height = "100%" : overlay.style.height = "0%"
}

x.addEventListener('click', toggleMenu, false);
* {box-sizing: border-box;}

body {
    margin: 0;
    font-family: 'Lato', sans-serif;
}

#overlay {
  height: 0%;
  width: 100%;
  background-color: rgba(0,0,0);
  background-color: rgba(0,0,0, 0.9);
  overflow-y: hidden;
  position: fixed;
  margin: 0px;
  z-index: 1;
  transition: 0.5s;
}

#overlay > a {
  list-style-type: none;
  text-decoration: none;
  color: #818181;  
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 1.8em;
  padding: 15px 0;
  display: block;
}

#overlay a:hover, #overlay a:focus {
  color: #f1f1f1;
}

#menu-toggle {
  cursor: pointer;
  display: -webkit-flex;
  display: -moz-flex;
  display: flex;
  -webkit-flex-wrap: nowrap;
  -moz-flex-wrap: nowrap;
  flex-wrap: nowrap;
  width: 90px;
  margin: 20px 0 0 0;
  right: 10%;
  -webkit-justify-content: center;
  -moz-justify-content: center;
  position: absolute;
  z-index: 999;
}

div, #menu {
  margin: auto;
}

[id*="bar"] {
  width: 30px;
  border-bottom: medium solid black;
  border-radius: 25px;
  margin-bottom: 5px;
}

.active #bar1 {
  -ms-transform: rotate(-45deg) translate(-3px, 10px); /* IE 9 */
  -webkit-transform: rotate(-45deg) translate(-3px, 10px); /* Safari */
  transform: rotate(-45deg) translate(-3px, 10px);
  transition: 0.4s;
}

.active #bar2 {
  opacity: 0;
  transition: 0.4s;
}

.active #bar3 {
  -ms-transform: rotate(45deg) translate(-1px, -8px); /* IE 9 */
  -webkit-transform: rotate(45deg) translate(-1px, -8px); /* Safari */
  transform: rotate(45deg) translate(-1px, -8px);
  transition: 0.4s;
}
<header>
  <nav> 
    <div id="overlay">
      <a href="javascript:void(0)">&times;</a>
      <a href="">Home</a>
      <a href="">Travels</a>
      <a href="">Tutorials</a>
      <a href="">Books</a>
      <a href="">About Me</a>
    </ul>
  </nav>
  </header>
  
  <div id="menu-toggle">
    <div id="container">  
      <div id="bar1"></div>
      <div id="bar2"></div>
      <div id="bar3"></div>
    </div><span id="menu">Menu</span>
  </div>

