What will print, hmmmm

Hi everyone - I’m beginning this coding program and I’ve been stuck on this question. Instead of trying to retake the quiz every time, I wanted to get direct help about this question.

var temp = 90
if temp < 70 {
print (“it’s cold outside”)
} else if temp > 71 {
print (“it’s hot”)
} else {
print (“it’s nice out”)
}

What will this print? I keep answering “it’s nice out” because I truly think that’s the answer but I keep getting it wrong. Can someone explain to me?

1 Like

Read each of the bits of the if statement top-to-bottom, because that's the order they'll be evaluated.

If the temperature is below 70, then...well, that's not the case, it's above 70. I'll keep going and skip this block.

Okay, now if that wasn't true, and the temperature is greater than 71...oh! since the temperature is greater than 71, this is the block I should start running. I'll print 'it's hot'.

Now I'll skip over the else, because I decided to execute the 2nd block.

2 Likes

It will print “Everyone’s dead.” At 90°C, the oceans would be about to boil. :stuck_out_tongue:

But jokes aside, @harlanhaskins beat me to the real answer.

3 Likes

To flip it around though, and maybe help you figure out the error you're having: why do you think it will print "it's nice out"?

1 Like

Thank you so much, once you explained it...it’s like “duh”, so much information my brain is melting on simple things. Thanks again!