Working on a function that checks if a user is logged in or out. If logged in, Log In button is removed and Log Out button displays. If current state is logged out, then Log In is displayed and Log Out is removed.
It's running in two different functions loggedIn();
and loggedOut();
. Each function is built out with ternary operators.
Is there a way to combine these into one function that checks for all conditions? Like loggedCheck();
so I don't have two different functions running.
Just looking to be more efficient and not over-code things.
isLoggedIn = false;
function loggedIn() {
isLoggedIn == true ? login.style.display = 'none' : login.style.display = 'block';
}
function loggedOut() {
isLoggedIn == true ? logout.style.display = 'block' : logout.style.display = 'none';
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
<body onload="loggedIn(); loggedOut();">
<div class="container py-3">
<button class="btn btn-md btn-primary" id="login">Log In</button>
<button class="btn btn-md btn-primary" id="logout">Log Out</button>
</div>
</body>