0
opening FULLSCREEN MENU with ONCLICK function
Hello everyone, I am trying to make sure that when I click on a div (3 bars) to open a fullscreen menu. And close when I click again. The menu opens without any error, but it is not closing as it show. How to solve? Thank you!! https://code.sololearn.com/WP21HQ2raVl3/?ref=app
8 Answers
+ 6
JoĆ£o Hoffman write var men = 0; outside the function. Then it will work.
It's happening because variable men always initialise with 0 so it's not going in else part. So you need to write var men = 0 outside the function. Means you need to declare variable men globally.
https://code.sololearn.com/WGHBs855m66y/?ref=app
+ 4
Since your men variable is inside function, everytime you call it, it's value will be 0.
Move it to global scope.
Tips:
Don't use numbers for this kind of task, use booleans.
[optional] you should use appropriate names that makes sense in your code, this increases your code readability.
+ 3
var isOpen = false;
if (isOpen) {
//Do the code to close sidebar
} else {
//Do the code to open sidebar
}
+ 3
JoĆ£o Hoffman Check again. I updated with boolean value.
0
How would I adapt to boolean?
0
AJ Anant - C#/Java Challenger OMG MAN, TY!!!
I LOVE YOU
0
Thank you all
0
you are amazing!!