0
Javascript help (Struggling) _learner
I need help with the "if" statement. I want the G to display= "none" when X is display ="none". Or else G="display:block. this is the code: https://code.sololearn.com/W36vsPDCWqiC/#js please let me know if you don't understand the question.
15 Answers
+ 2
Ok let me try
+ 1
can you tell me
What exactly you are trying to create,
what's the concept
+ 1
Generally x will hidden but on click of on button it will display ... Am i right?
+ 1
X is generally visible (it's on ). the "OFF" button turns it off. and the on button will turn it back on.
So if X is OFF, G should be off too.
+ 1
Y.K you said the styling wasn't proper. Does it mean that was part of the error?
0
If you are looking for why the if statement doesn't work, it's beacuse after the statement you put a semicolon, when you shouldn't have done that
if (condition); {} else {}
^
Remove semicolon
0
Airree , Did it work for you when you removed the semicolon? because it doesn't for me. If you are on a computer, it will tell you what the problem is. there are about 2 or 3 errors.
0
Yes, can you tell me what kind of errors there are?
0
Okay, if the "if" statement doesn't work, you can use this:
b.style.display = a.style.display == "block"? "block": "none"
0
On line 14 "Assignment in conditional expression"
and line 17 "expected an identifier and instead saw 'else'. Missing ";" before statement.
Those are the errors. You can redo the if statement in a way that makes sense if you want instead of just trying to fix it.
0
Also, a better way of hiding elements is the visibility property:
b.style.visibility = "visible"/"hidden"
0
I see now:
in the condition, you used only one =, instead ==
0
Hey, the condition works. there is only one other problem now. the line 17.
0
Y.K , I'm trying to make the G (G) display="none" if/ when X .display ="none". else G should be display="block".
The On and Off button control X (off/on). So if X is off, G should be off too.
You will see the X, G,.... when you load the code.