Home › Forums › JavaScript › True or False Statements …
- This topic is empty.
-
AuthorPosts
-
December 18, 2013 at 2:05 pm #158640
nathan
Participantif(0) { console.log("Welcome"); } else { console.log("Don't let the door hit ya where the good Lord split ya!"); }
By default since an if statement should be true with the following else statement being false? especially when the two statements are like the above. Right?
December 18, 2013 at 2:11 pm #158641TheDoc
MemberWhat’s the question?
December 18, 2013 at 2:27 pm #158644nathan
Participantwhen an if / else is set up … the statement immediately after … in this case … Welcome … is always True … and the preceding statement … Dont let the door hit ya … is always False. Right?
December 18, 2013 at 5:04 pm #158658TheDoc
MemberYes. If the first condition is met the
else
will never run. But I’m still not sure I understand your question. I feel like you’re trying to ask something more complicated but can’t quite get the words right.December 18, 2013 at 6:06 pm #158664nathan
ParticipantI took a test with similar question … and the latter statement was true and the former … was false … and while I got the question right … I just thought it was odd …
I did some reading through my college books and I felt like I was right and the test was wrong …
Perhaps you could explain a scenario where a developer would want the … if … statement to be false and the … else … to be true … SMH … im rambling so I will stop now …
December 18, 2013 at 8:20 pm #158668__
ParticipantPerhaps you could explain a scenario where a developer would want the … if … statement to be false and the … else … to be true …
It’s not an issue of “wanting” the if to be true or false, it’s an issue of knowing if it is true or false.
if( userSaidTurnLeft ){ turnLeft(); } else{ turnRight(); }
I don’t care which way they turn, I just need to know what their choice was.
when an if / else is set up … the statement immediately after … in this case … Welcome … is always True … and the preceding statement … Dont let the door hit ya … is always False. Right?
I’m not sure I follow your question.
As @TheDoc answered, If the
if
is true, then theif
block will be executed. If it’s false, theelse
block will execute.However, in your original example, the
if
condition is not true. Watch out for that door.(Also, just to make sure we are not misunderstanding, the
else
is not the “preceding” statement; it is the following statement.)December 19, 2013 at 8:54 am #158746nkrisc
ParticipantYour example will run the
else
block because as I understand it, JavaScript considers0
to befalse
December 19, 2013 at 9:47 am #158763nathan
Participant@TheDoc … perhaps I could record my screen and post it on youtube … so you could hear me say what Im thinking … cause its kinda tough to type out exactly what it means …
@Traq … your right … its not the preceding …
@nkrisc … your right also …
Im just a little tangled up right now … thanks for the input …
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.