JavaScript bootcamp · Lab 03

Celsius to Fahrenheit

easyMath8 minLesson: Math

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read a Celsius temperature (it may have decimals) and log it in Fahrenheit.

F = C × 9/5 + 32. Log the result with exactly one digit after the decimal point.

Input. One line: a number.

Output. Fahrenheit to one decimal, e.g. 98.6

Constraints

  • -273.15 ≤ C ≤ 1000

Examples

Example 1 — Body temperature.
Input
37
Output
98.6
Example 2 — toFixed(1) keeps the trailing .0.
Input
100
Output
212.0
Hint
  1. JavaScript division is already floating-point: 9 / 5 is 1.8.
  2. Number.prototype.toFixed(1) rounds and formats: (value).toFixed(1).
Show correct code

Peek only after you have tried. You can still Check your own version.

const c = Number(readLine());
console.log((c * 9 / 5 + 32).toFixed(1));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.