opening FULLSCREEN MENU with ONCLICK function | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
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

4th Jul 2020, 5:22 PM
Jo√£o Hoffman
Jo√£o Hoffman - avatar
8 Respostas
+ 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
4th Jul 2020, 5:27 PM
AÕĘJ
AÕĘJ - avatar
+ 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.
4th Jul 2020, 5:31 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 3
var isOpen = false; if (isOpen) { //Do the code to close sidebar } else { //Do the code to open sidebar }
4th Jul 2020, 5:33 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 3
Jo√£o Hoffman Check again. I updated with boolean value.
4th Jul 2020, 5:38 PM
AÕĘJ
AÕĘJ - avatar
0
How would I adapt to boolean?
4th Jul 2020, 5:32 PM
Jo√£o Hoffman
Jo√£o Hoffman - avatar
0
AJ Anant - C#/Java Challenger OMG MAN, TY!!! I LOVE YOU
4th Jul 2020, 5:33 PM
Jo√£o Hoffman
Jo√£o Hoffman - avatar
0
Thank you all
4th Jul 2020, 5:33 PM
Jo√£o Hoffman
Jo√£o Hoffman - avatar
0
you are amazing!!
4th Jul 2020, 6:07 PM
Jo√£o Hoffman
Jo√£o Hoffman - avatar