Challenge 7 Megathread

Thanks for your input willianchu! I believe I have that code correctly, I pass the first test which asks for an object. Any other suggestions?

nevermind, that did fix my problem. thank you so much!

that worked! thank you so much :slight_smile:

Hi, Im a little confused here. I’ve passed the “return an object” test but failed the other two. Not sure what I’m doing wrong.

const storeWeatherConditions = (temperature, condition, windSpeed, windDirection) => { let weather = {temperature, condition, windSpeed, windDirection};
weather.temperature = Math.round((weather.temperature - 32) * 5/9);
weather.windSpeed = Math.round(weather.windSpeed/2.237);
weather = Object.keys(weather);
return weather;
}

@ironlithium can I join your team? I see one of your team members is at 0.

Nevermind I removed the object.keys line and it fixed it

Re-wrote code, all good and passed now!! Went back to the objects doc and saw where I went wrong understanding properties/keys/values and creating objects. Thanks again!

Two main methods to look into are Math.round() and Math.floor(). They are very similar in implementation with slight variation in the outcome. Lighthouse is throwing a bit of a curveball and I love it!

1 Like

A little tricky but I got it in three lines!

Note to self: Always look at your brackets! big difference between (), [] and {}.

I’m running into something strange here, and I’m not sure if it’s because I’m missing something silly. I’ve passed the first two tests, but for the final test, it says I am getting a value of 2 instead of 9.

It’s like there is actually more than one calculation being applied than just “windSpeed/2.237” and it is being done after each test?

Using “console.log(weatherConditions.windSpeed);” to see the value of windSpeed

Capture2

Code:

var temperature = 32;
var condition = “Sunny with small clouds”;
var windSpeed = 20;
var windDirection = “NNE”;

function storeWeatherConditions(temperature, condition, windspeed, windDirection) {

temperature = Math.round((temperature-32)*5/9);
windSpeed = Math.round(windSpeed/2.237);

var weatherConditions = {
temperature,
condition,
windSpeed,
windDirection
};

return(weatherConditions);

//console.log(weatherConditions.windSpeed);

}

The object that you’re creating has only the values, it misses the property’s name.

JavaScript Objects (w3schools.com) :point_left:

1 Like

I eventually figured it out, but I’m still not clear all the reasons why my initial attempt didn’t work. I originally had something like this:

const storeWeatherConditions = (temperature, condition, windSpeed, windDirection) => {

 this.temperature = Math.round((weatherConditions.temperature - 32) * 5/9);;
 this.condition = condition;
 this.windSpeed = Math.round(weatherConditions.windSpeed/2.237);;
 this.windDirection = windDirection;

return {
this.temperature,
this.condition,
this.windSpeed,
this.windDirection

}

// Code here!

// Remember to return an object!
};

I passed the first two tests with returning an object and keys, but it kept saying my values, especially the converted values, didn’t pass through the function. I eventually solved it by defining a weatherConditions object and specifically converting the temperature and windSpeed properties, but I still don’t understand the difference between returning a specific object like ‘weatherConditions’ and the return statement I originally had.
that’s one part of javascript object I don’t fully understand yet.

Thanks:)

How did you do it in three lines?
I got it down to six lines…

is there such a thing as nesting in javascript? like instead of ; you just calculate all those values on one line?

1 Like

It worked, replaced the semicolon; with a comma, until the last value and counts as one line.

Hmm, I must’ve messed up on the brackets for that to work, I replaced the semi colons for commas and it didn’t run. Did you need to use [] or () instead of {}?

square brackets…cool.

currentWeather.temperature = Math.round((temperature - 32) * 5/9), currentWeather.windSpeed = Math.round(windSpeed / 2.237), currentWeather.condition = condition, currentWeather.windDirection = windDirection;

This worked for me as one line, no brackets

1 Like

Well, since we’re only really focusing on the conversion of both windSpeed and temperature, In my code i just let:

windSpeed = Math.round((insert formula here formula)) ;
temperature = Math.round((insert formula here)) ;

// I disregarded manipulating windDirection and condition since they did not need to be manipulated and just included in the returned object.

return {temperature, condition, windSpeed, windDirection} ;

// I used the {} to denote a single object as per the expected outcome wants, and i’m not sure if the order of the elements in this object (array maybe?) matters but this is my three-liner.

2 Likes

Ahh interesting, thanks!

1 Like