Defining a variable using comparison operators

Joined
Dec 17, 2022
Messages
4
Reaction score
0
Hello, I'm very new to coding and I'm trying to write a very basic program to tell the user what to wear when it's certain temperatures. I have it set so that it will produce a random number between 0 and 30. I am wondering how I write a statement for what happens if it's between two numbers, 10 and 20. So far I have

if (weather <= 10) {
(forcast = "cold");
} else if (weather < 20 > 10 ) {
(forcast = "warm");

I also tried (weather 20 < 10), (weather 10 > 20)
 
Joined
Jul 3, 2022
Messages
93
Reaction score
23
JavaScript:
function say(weather){
        if(weather <= 10){
           forcast = 'cold';
        }
        else if(10 < weather && weather < 20){
           forcast = 'warm';
        }
        else{
           forcast = 'surpise ;)';
        }
      console.log(forcast);
    }
 
    say(10); // warm
    say(14); // warm
    say(9); // cold
    say(20); // surpise ;)
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
Code:
//Example
if(weather < 20 && weather>10)

&& is the operater for "and"

|| is the operator for "or"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top