-3

I'm have several if statements which prints out the strings from corresponding list depending on the input (feelsLike).

Code

First it prints out the range in which feelsLike is in and then adds everything in the list to the string. From the console, we can check that feelsLike is 14 but somehow it executes the console.log in the second if statement (6 <= feelsLike <= 9). Can you please tell me what I'm doing wrong?

Console Output

  • 5
    If you could, please edit *your actual code* as text into your question - images of code *alone* are [tedious and difficult](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question) to work with and debug. It forces those who would otherwise love to help you to [transcribe your image](https://idownvotedbecau.se/imageofcode) first, which is a waste of time. – CertainPerformance Oct 28 '19 at 02:16

1 Answers1

4

6 <= feelsLike <= 9

This doesn't work the way you want it to. It's not going to check whether feelsLike is between 6 and 9. Instead, it's going to check if 6 <= feelslike, and that resolves to either true or false. Supposing its false, the next thing it will check is false <= 9. This comparison doesn't make much sense, so javascript turns the false into a number, specifically 0 (true would turn into a 1). 0 is less than or equal to 9, so the end result is true.

Instead, do 6 <= feelsLike && feelsLike <= 9

Nicholas Tower
  • 72,740
  • 7
  • 86
  • 98