Thứ Sáu, 27 tháng 3, 2015

cấu trúc lựa chọn switch - case trong cách xác định thứ hiện tại trong tuần


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--  2 dòng var là trả lại thứ trong tuần -->
var d = new Date();
var theDay = d.getDay();
switch(theDay)
{
case 1: document.write(" Monday");
break;
case 2: document.write(" Tuesday");
break;
case 3: document.write(" Wednesday");
break;
case 4: document.write(" Thirsday");
break;
case 5: document.write(" Friday");
break;
case 6: document.write(" Saturday");
break;
case 0: document.write(" Sunday");
break;
default:
document.write(" I'm looking forward to this weekend");
}
</script>
</head>

<body>
</body>
</html>

Không có nhận xét nào: