+ 3

How do I fix this kind of if loop?

I have a couple of these in VXGEJF and I don't know what's wrong, do I need semicolons? Example: function newDoor() { if (keys = 0) { alert("The door is locked. You need the guard's keys.") } else if (keys = 1) { alert("The door is open. What lies beyond? Find out soon...") thanksUserJoshGreig() document.write("<head><style>body {background:#005f77;}h3 {background:#77f500;}#p {background:#050f77;color:#DDFFDD;}</style></head><div id=\"p\"><p>VXGEJF: THE GAME</p><p>More coming soon...</p><br><br><br><br><br><hr><h6>Current Version: Update 1.0.1(fixes) Date finished: 11:14AM Fri, August 14</h6>") keys = 0 } } (All the functions and variables are defined somewhere in the code) It's not that I got what I needed for the one output every time, I just checked. It only ever gives the second output. https://code.sololearn.com/WDVwh0O7oDhI/?ref=app

14th Aug 2020, 6:17 PM
Dustin 🇺🇸
12 Respuestas
+ 3
It should be working. Keys is declared as zero. In a function above it declares keys as 1 but you have to click a button. I'll try to move the function, but that shouldn't be the problem...?
14th Aug 2020, 6:25 PM
Dustin 🇺🇸
+ 3
It didn't work. It seems like everything I code fails. 😫
14th Aug 2020, 6:27 PM
Dustin 🇺🇸
+ 3
I tried that and it still didn't really work
14th Aug 2020, 6:41 PM
Dustin 🇺🇸
+ 3
Are you sure you want to use assignment instead of comparison?
15th Aug 2020, 7:54 PM
Artur
Artur - avatar
+ 3
if(keys = 0) is assignment if(keys == 0) is comparison
15th Aug 2020, 7:55 PM
Artur
Artur - avatar
+ 3
I think you're right, I must not have seen that...
15th Aug 2020, 7:55 PM
Dustin 🇺🇸
+ 3
Thanks
15th Aug 2020, 7:56 PM
Dustin 🇺🇸
+ 3
I think I forgot about this question, and it hasn't even been very long since I asked it... hehe...
15th Aug 2020, 7:57 PM
Dustin 🇺🇸
+ 2
You're welcome 👍
15th Aug 2020, 7:59 PM
Artur
Artur - avatar
+ 1
You should use ; after each statement. After defining and assigning variables. After setting or getting values. etc.. For better result. It is very important to let the system know that how many function it has to do. In python you will found it as indentation error means have to indent after statements.so follow these basics to avoid errors.
14th Aug 2020, 6:40 PM
Divya Mohan
Divya Mohan - avatar
+ 1
What is beyond your expectation here explain plz. Code is large to analyse and new game for me.
14th Aug 2020, 6:56 PM
Divya Mohan
Divya Mohan - avatar
+ 1
please use == inside if-else. becoz if u put k=0 this is like assignment. k is initialized with 0.so instead of k=0 0 is placed.. so the if(k=0) is looks like if(0). but if u use k==0. this will be comparison. so k==0 will be true if k=0 else false. so the if(k==0) is looks like if(1) if k=0 else false. Hope u got it. 😊😊😊😊
16th Aug 2020, 11:11 AM
BeastyDSK
BeastyDSK - avatar