TypeScript: Convert Celsius to Fahrenheit

🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.

▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube

▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube

1. Introduction

Temperature conversion is a common task in various applications. In this blog post, we will walk through a TypeScript program that converts a temperature from Celsius to Fahrenheit.

2. Program Overview

The formula to convert Celsius to Fahrenheit is (Celsius * 9/5) + 32. Our program will define a function celsiusToFahrenheit that takes a number (Celsius temperature) and returns the equivalent Fahrenheit temperature.

3. Code Program

// Function to convert Celsius to Fahrenheit
function celsiusToFahrenheit(celsius: number): number {
    return (celsius * 9/5) + 32;
}

// Test the function
const celsiusTemperature = 25;
const fahrenheitTemperature = celsiusToFahrenheit(celsiusTemperature);
console.log(`${celsiusTemperature}°C is equal to ${fahrenheitTemperature}°F.`);

Output:

25°C is equal to 77°F.

4. Step By Step Explanation

1. We start by defining the celsiusToFahrenheit function. This function takes in a single argument: the temperature in Celsius.

2. Inside the function, we use the formula (Celsius * 9/5) + 32 to convert the Celsius temperature to Fahrenheit.

3. We then test the function with a sample Celsius value of 25.

4. The result, which is the temperature in Fahrenheit, is then logged to the console.

My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare