Kelvin Weather Project - Question from a Newb

Hello, I am brand new and making my way through the JavaScript Introduction & React Coursework.

I just finished the Kelvin Weather project and was excited that I made it through to the end without having to use any hints and returned the correct values.

Once I finished, I went back to check against the “hints” and noticed that how I arrived at the values was different than how the code is written in the hint section.

Please provide feedback on whether the way I set my floor methods from the Math library on the variables is an acceptable way of coding or if creating the additional lines of code as demonstrated in the hints section is a superior method.

If so, can you explain why the way I did it is not preferred?

//Temp in Kelvin
const kelvin = 0;
//Convert to Celsius
const celsius = kelvin - 273;
//Convert to Fahrenheit, rounded down
let fahrenheit = Math.floor(celsius * (9 / 5) + 32);
//Displays temp in Fahrenheit
console.log(The temperature is ${fahrenheit} degrees Fahrenheit.);
//Convert to Newton, rounded down
let newton = Math.floor(celsius * (33/100));
//Displays temp in Newton
console.log(The temperature is ${newton} degrees Newton.);

You’re doing fine. The way you’re writing is the preferred way to code and what you can expect to see. Just don’t take it to far with everything being on one line as it can make it more difficult to debug or for others to understand your code.

2 Likes