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.

14th May 2019, 1:41 PM
Ginfio
Ginfio - avatar
15 Answers
14th May 2019, 3:39 PM
Bug Slayer
+ 2
Ok let me try
14th May 2019, 3:24 PM
Bug Slayer
+ 1
can you tell me What exactly you are trying to create, what's the concept
14th May 2019, 3:08 PM
Bug Slayer
+ 1
Generally x will hidden but on click of on button it will display ... Am i right?
14th May 2019, 3:20 PM
Bug Slayer
+ 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.
14th May 2019, 3:21 PM
Ginfio
Ginfio - avatar
+ 1
Y.K you said the styling wasn't proper. Does it mean that was part of the error?
14th May 2019, 5:39 PM
Ginfio
Ginfio - avatar
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
14th May 2019, 1:51 PM
Airree
Airree - avatar
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.
14th May 2019, 2:54 PM
Ginfio
Ginfio - avatar
0
Yes, can you tell me what kind of errors there are?
14th May 2019, 2:56 PM
Airree
Airree - avatar
0
Okay, if the "if" statement doesn't work, you can use this: b.style.display = a.style.display == "block"? "block": "none"
14th May 2019, 3:04 PM
Airree
Airree - avatar
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.
14th May 2019, 3:05 PM
Ginfio
Ginfio - avatar
0
Also, a better way of hiding elements is the visibility property: b.style.visibility = "visible"/"hidden"
14th May 2019, 3:05 PM
Airree
Airree - avatar
0
I see now: in the condition, you used only one =, instead ==
14th May 2019, 3:07 PM
Airree
Airree - avatar
0
Hey, the condition works. there is only one other problem now. the line 17.
14th May 2019, 3:14 PM
Ginfio
Ginfio - avatar
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.
14th May 2019, 3:16 PM
Ginfio
Ginfio - avatar