I cant find the flaw in my code

Joined
Dec 17, 2022
Messages
4
Reaction score
0
This code is supposed to give me a very simple output of

the temperture (randomly decided)
the "forecast" (hot, moderate, and cold)
and the clothing for the day

it's giving me the first two but then it's skipping right to valid after that so where am I going wrong with the second else if statement? Also, if anyone has any suggestions to find flaws faster I would love some tips there too!
Thank you in advance!

JavaScript:
//create a simple program that will make a clothing decision based on the weather. 1. You need a changing variable for temperture and display it.;
let temp = Math.floor(Math.random() * 30);
console.log(temp);
let forecast = "";

//2. Determine what the forecast is based on that temperture;
if (temp <= 10) {
  forecast === "cold";
  console.log("cold");
} else if (temp >= 11 && temp <= 20) {
  forecast === "moderate";
  console.log("moderate")
} else {
  forecast === "hot";
  console.log("hot");
}

//Determine what to wear based on the forecast
if (forecast === "cold") {
  console.log("bundle up!");
} else if (forecast === "moderate") {
  console.log("wear a sweater");
} else if (forecast === "hot") {
  console.log("sunscreen")
} else {
  console.log("invalid")
}
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
use 'things' like
forecast = "cold";
and not
forecast === "cold";
in the (2.) section.
Because you're assigning not comparing
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
So post your code
But I bet you changed stuff in the if (forecast === "cold") loop and I told you not to do that
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top