songin.dev님의 블로그

Kelvin Weather 본문

Developer/Langauge

Kelvin Weather

songin.dev 2022. 6. 17. 22:49
728x90
Kelvin Weather 

켈빈 온도로 예측한 온도 화씨로 변환하기 + 뉴턴 포함

// today forecast kelvin temp
const kelvin = 293;

// celsius temp
const celsius = kelvin - 273;

// fahrenheit temp
let fahrenheit = celsius * (9 / 5) + 32;

// fahrenheit equation
fahrenheit = Math.floor(fahrenheit);

console.log(`The temperature is ${fahrenheit} degrees Fahrenheit.`);

let newton = celsius * (33 / 100);

newton = Math.floor(newton);

console.log(`The temperature is ${newton} degrees Newton.`);

 

해설
1. const kevlin 변수에 켈빈 온도 값 선언과 함께 초기화
2. const celsius 변수에 kelvin을 산수연산자를 통해 값 초기화
3. 화씨를 구하는 방정식을 대입하여 화씨 온도 값 초기화
4. Math.floor를 함수를 통해 화씨 온도 소수점 이하 반올림
5. 콘솔창에 메시지와 함께 템플릿 레터럴을 이용하여 화씨 값 출력
6. 3~5번 뉴턴을 대입하여 반복
반응형
Comments