개의 나이를 사람의 나이로 대략 변환하는 아래와 같은 공식이 있다고 한다.
(사람의 나이) = ((개의 나이) - 2) x 4 + 21
이것을 이용해 개의 나이를 입력하면 사람의 나이로 변환하여 알려주는 코드를 JavaScript로 만들어보자
// 1. dog의 age 얻기
const newDogAge = prompt("How old is your dog's age?");
// 2. human age로 변환하는 공식 만들기
const humanAge = ((newDogAge-2)*4)+21;
// 3. 계산된 humanAge를 alert로 전달하기
alert("Your dog is "+newDogAge+ " years old and it means " + humanAge + " years old as a human age ");
고양이 나이 계산기도 업로드 해주세요 ~ 😸