Convert a temperature, and show the result as a whole number.
What to build
A program that reads a temperature in Celsius and prints it in Fahrenheit.
Requirements
- Read the temperature in Celsius. It may have decimals.
- Calculate Fahrenheit with
F = C x 9 / 5 + 32. - Round the result to the nearest whole number.
- Print
C C is about F F.
Input
One line: a number.
Output
One line, as in the example.
Constraints
The temperature is from -100 to 100.
Example
Input:
36.6
Output:
36.6 C is about 98 F
Why it works
The calculation needs a number, but the rounding happens only at the end, so no accuracy is lost along the way. Printing the value inside a template string shows the Celsius figure exactly as it was read.
Examples
Example 1 · Input
25
Expected output
25 C is about 77 F
Example 2 · Input
36.6
Expected output
36.6 C is about 98 F
Hints
Hint 1
The formula is F = C x 9 / 5 + 32.
Hint 2
Math.round(x) gives the nearest whole number.
Hint 3
Print the Celsius value as it was typed.
Solution
Show one correct solution (try it yourself first)
const celsius = Number(prompt());
const fahrenheit = Math.round(celsius * 9 / 5 + 32);
console.log(`${celsius} C is about ${fahrenheit} F`);