본문 바로가기
오즈코딩스쿨/[JavaScript]

02.Chapter2.조건문과 반복문/5 조건문

by Sowon Kim 2025. 9. 10.
<script>
	const h1 = document.querySelector('h1')
    const p = document.querySelector('p')
    
    /*
    const isThere = confirm("제목 표시를 할까요?")
    if(isThere){
    	h1.textContent = "문서의 제목!!"
    }
    */
    
    if(isThere){
    	h1.textContent = "당신이 내야 할 버스요금은?"
    }
    
    const age = parseInt(prompt("나이가 어떻게 되세요?"))
    
    if(age >= 20){
    	p.textContent = "1250원입니다!"
    }else if(age >= 8){
    	p.textContent = "760원입니다!"
    }else{
    	p.textContent = "무료입니다!"
    }
    
</script>