본문 바로가기
Front-End/JavaScript

Learn JavaScript_Introduction

by SoyeonCha 2022. 7. 14.

Kelvin Weather

//Current temperature in kelvin degrees.
const kelvin = 0;
//Convert kelvin to celsius
const celsius = kelvin-273;
//Convert celsius to fahrenheit
let fahrenheit = celsius * (9/5) + 32;
//Round down fahrenheit variable
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.`)

 

Dog Years

//my current age
const myAge = 23;
//early years
let earlyYears = 2;
earlyYears *= 10.5;
//laterYears
let laterYears = myAge-2;
laterYears *= 4;
console.log(earlyYears);
console.log(laterYears);
//my age in dog years
let myAgeInDogYears = earlyYears + laterYears;
//Change my name to lower case
let myName = "Soyeon".toLowerCase();
//Show my age in dog years
console.log(`My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years.`)