Celsius to Fahrenheit
Programming Basics · JavaScript
TASK
Problem
Given Celsius temperature `c`, convert it to Fahrenheit using `F = C * 9 / 5 + 32`.
EXAMPLE
Example
25
77.0
LIMITS
Constraints
c ≥ -273.15
LEARN
Theory for this problem
+
### Celsius to Fahrenheit
JavaScript arithmetic works with numeric values stored in variables. A clear solution reads the needed values, computes the formula with `+`, `-`, `*`, `/` or `**`, and prints only the final result.
NEED HELP?
Hints
+
['Write the formula using named intermediate values if it contains more than one operation.', 'Before printing, output only the computed result and do not add explanatory text that is absent from the required format.']
ANSWER
Solution
+
const fs = require('fs');
const celsius = Number(fs.readFileSync(0, 'utf8').trim());
const fahrenheit = celsius * 9 / 5 + 32;
console.log(Number.isInteger(fahrenheit) ? fahrenheit.toFixed(1) : fahrenheit);