on
BMI Calculator 만들기 / Leap Year (윤년) 찾기 - 자바스크립트 challenge
BMI Calculator 만들기 / Leap Year (윤년) 찾기 - 자바스크립트 challenge
BMI Calculator 만들기
let yourHeight = prompt(" What's your height?"); let yourWeight = prompt(" What's your weight?"); let interpretation = Math.round(yourWeight/(Math.pow(yourHeight/100,2))); function bmiCalculator (weight, height) { if (interpretation > 24.9){ return "Your BMI is "+ interpretation + ", so you are overweight." }else if(interpretation>=18.5 && interpretation <= 24.9){ return "Your BMI is "+ interpretation + ", so you have a normal weight." }else{ return "Your BMI is "+ interpretation + ", so you are underweight." } } bmiCalculator(yourWeight,yourHeight);
Leap Year 찾기
leap year이란?
일년이 366일이고, 2월에 하루가 더 있는 년도이다.
그래서 특정한 년도가 윤년인지 알아보기 위한 코드를 작성해보자.
만약 4로 균등하게 나누어진다면 연도는 윤년이다.
4로 나누어지고 100으로는 나누어 지지 않으면 윤년이다.
연도가 4,100,400으로 나누어 떨어지는 해는 윤년이다.
방법1
function isLeap(year) { /**************Don't change the code above****************/ let leapYear = year ; if ((leapYear % 4 === 0) && (leapYear % 100 === 0 ) && (leapYear % 400 === 0 ) ){ return " Leap year."; } else if ((leapYear % 4 === 0) && (leapYear % 100 !== 0 )){ return " Leap year."; } else if((leapYear % 4 === 0) && (leapYear % 100 === 0 ) && (leapYear % 400 !== 0 )){ return " Not leap year."; }else{ return " Not leap year."; } /**************Don't change the code below****************/ } isLeap(2000);
방법2
function isLeap(year) { if (year % 4 === 0) { if (year % 100 === 0) { if (year % 400 === 0) { return "Leap year"; } else { return "Not leap year"; } } else{ return "Leap year"; } } else { return "Not leap year"; } } isLeap(1989);
from http://dhstory311.tistory.com/210 by ccl(A) rewrite - 2021-10-27 22:01:06