嘿,我希望在零售商店的網站上顯示一個指示符以便打開(非常像Yelp的指示符「立即打開」)。我已經想出瞭如何在每天的設定時間內完成它(例如下文)。如何在if else語句中聲明兩個條件
但是這家店週五的收盤時間不同&星期六,&星期天休息。我希望能找到一種方法來將這些變量也納入這個等式中。
或考慮到這些變化,以使網站上的指標準確。
// JavaScript Document
var today = new Date();
var dayNow = today.getDay();
var hourNow = today.getHours();
var shopStatus
if (dayNow = 0) {
shopStatus = 'See you on Monday';
}
// Regular Hours for Monday - Thursday
// night time message
else if (hourNow > 21) {
dayNow < 4
shopStatus = 'Open at 7am';
}
// closed hours message
else if (hourNow >18) {
dayNow < 5
shopStatus = '<p class="red">Closed Now</p>';
}
// 6:30pm closing soon message
else if (hourNow > 17.5) {
dayNow < 4
shopStatus = 'Closing soon';
}
// Mon - Thurs. open hours message
else if (hourNow > 7) {
dayNow < 4
shopStatus = 'Open Now';
}
// 6:30am opening soon
else if (hourNow > 6.5) {
dayNow < 4
shopStatus = 'Opening Soon';
}
document.write('<p>' + shopStatus + '</p>');
像'dayNow <4'這樣的聲明什麼都不做。 – Pointy
另外,我認爲你正在尋找[&&'運營商](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators) – Pointy
dayNow = 0只是設置dayNow爲0 – djechlin