Whiteship's Note

'자바스크립트 조건문'에 해당되는 글 1건

  1. 2007.07.09 JavaScript If...Else와 Switch Statement

JavaScript If...Else와 Switch Statement

AJAX/JavaScript : 2007.07.09 12:25


참조 :
http://www.w3schools.com/js/js_if_else.asp
http://www.w3schools.com/js/js_switch.asp

if문 예제
<script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time<10)
{
document.write("<b>Good morning</b>")
}
else if (time>=10 && time<16)
{
document.write("<b>Good day</b>")
}
else
{
document.write("<b>Hello World!</b>")
}
</script>

switch문 예제
<script type="text/javascript">
//You will receive a different greeting based
//on what day it is. Note that Sunday=0,
//Monday=1, Tuesday=2, etc.

var d=new Date()
theDay=d.getDay()
switch (theDay)
{
case 5:
  document.write("Finally Friday")
  break
case 6:
  document.write("Super Saturday")
  break
case 0:
  document.write("Sleepy Sunday")
  break
default:
  document.write("I'm looking forward to this weekend!")
}
</script>

둘 다 자바의 조건문이랑 완전 같기 때문에 pass
&&와 || 연산자 사용도 같습니다.

'AJAX > JavaScript' 카테고리의 다른 글

JavaScript Try...Catch Statement  (0) 2007.07.09
JavaScript Events  (2) 2007.07.09
JavaScript For Loop와 While Loop  (1) 2007.07.09
JavaScript Functions  (0) 2007.07.09
JavaScript Popup Boxes  (0) 2007.07.09
JavaScript Operators  (0) 2007.07.09
JavaScript If...Else와 Switch Statement  (0) 2007.07.09
JavaScript Variables  (0) 2007.07.09
JavaScript Where To ...  (0) 2007.07.09
JavaScript How To ...  (0) 2007.07.09
Introduction to JavaScript  (0) 2007.07.09
top