Business and technology shouldn't be difficult

Kelvin Weather — JavaScript Project

Published by Atul Kumar Pandey on June 9, 2022.

In Codecademy, when learning the basics of JavaScript we are given a project of building Kelvin weather, where we have to convert Kelvin to Celsius, then to Fahrenheit.

In this article, I’ve explained the javascript codes with explanations.

Kelvin thermometers

Data we’ve already with us:

  • Today’s weather forecast: 293 Kelvin.
  • Celsius is similar to Kelvin — the only difference is that Celsius is 273 degrees less than Kelvin.
  • Fahrenheit = Celsius * (9/5) + 32

So let’s begin. Here begins the javascript code.

// We set constant value for kelvin which is 293.
const kelvin = 293;

// We set celsius value which is 273 less in kelvin.
const celsius = kelvin - 273;

// Used formula to sum fahrenheit.
let fahrenheit = celsius * (9 / 5) + 32;

// By using the .floor() method from the built-in Math object to round down the Fahrenheit temperature.
fahrenheit = Math.floor(fahrenheit);

// Outcome of above calculations.
console.log(`The current temprature is ${fahrenheit} degrees fehrenheit.`);

In the last line, I have used the backtick not the apostrophe symbol, do remember that.

The outcome of the above codes should be:

The current temprature is 68 degrees fehrenheit.

This is it. That’s how we can do this Kelvin weather project in javascript.

Categorized in Web Development and tagged in , , , .

Published by Atul Kumar Pandey

Atul Kumar Pandey is a creator of atulhost. Being a business management graduate, he has a flair for business writing but also likes to dabble in technological trends. He is a voracious reader and an avid tech tester and loves to try new things.

Leave a reply

Required fields are asterisked and email address will not be shared.