반응형
(Recub) function 을 호출하는 법
오늘의 퀘스트
very nice 한 나이 계산기 만들기.! (prompt()_를 사용하여)
*prompt는 사용자에게 메시지를 보여주고 값을 넣으라고 말한다.
const age = prompt("How old are you?"); //massame는 string, 이 상태에서 값을 기다린다. 잘 안씀 css를 적용시킬수도 없음.
//console.log(age); 대신에
console.log(typeof "15" typeof parseInt("15")); //이렇게 작성해야한다. string이 기본값.
//JaveScript를 일시정지시킴,브라우저로 할 수 있는 가장 직접적인 방법.cancle 을 누르면 null값을 리턴.
//console에 출력된 값은, num type 이 아니라 str type 이다.
type을 변경해보자 str에서 num 으로,,
parseInt 을 사용한다..
const age = parseInt(prompt("How old are you?"));
if (isNaN(age)) {
console.log("Pleas write a number");
} else {
console.log("Thank you for writing your age.");
}
'Developer' 카테고리의 다른 글
조건문 (conditionals) if-else (0) | 2021.12.27 |
---|---|
조건문 (conditionals) if-else (0) | 2021.12.27 |
#바닐라_자바스크립트_7 (0) | 2021.12.27 |
#바닐라_자바스크립트_7 (0) | 2021.12.27 |
#바닐라_자바스크립트_6 (0) | 2021.12.27 |