What would be the practical approach to the issue of this type?
I'm writing a function which aims to move the div left and right on toggle.
The approach I have decided to take is as below. Can someone explain why this is not working as I expect?
I'm aware that there may be another solution but this resolving this issue will allow me to use this practice for other scenarios.
If I understand correctly the bool can not be returned using return statement, but can the variable with bool in it?
For some reason my function is not reaching to "else if" statement which I thought it would after switching the bool inside of "if"...
The part of this code is basic so I will not include full script.
Code:
menuBtn = document.getElementById('mm');
menuBtn.onclick = function() {onMenuPress()};
let sidebar = document.getElementById('sidebar');
function onMenuPress() {
let move = true;
console.log(move);
if (move == true) {
sidebar.style.transform = "translate(-300px)";
let move = false;
console.log("pressed");
return move;
}
else if (move == false) {
sidebar.style.transform = "translate(100px)";
console.log("comeback");
}
Thanks for all responses in advance.