My variable normalWeek is equal to a certain time period, if this time period is true then the first condition will be executed if it is not the while loop will execute the second condition until variable normalWeek becomes true. But the problem is that when i execute the code the first condition that the loop finds to be true will be the only one executed even after another condition becomes true.
For example, variable normalWeek is true if it is 6am, but the loop will continue to execute this same condition even after it is not 6am, it basicaly ignore the other condition.
var date = new Date();
var hour = date.getHours();
var day = date.getDay();
var minute = date.getMinutes();
function goodSignal() {
console.log(b, 'Good Signal');
}
function badSignal() {
console.log(b, 'Bad Signal');
}
function sleep(miliseconds) {
var currentTime = new Date().getTime();
while (currentTime + miliseconds >= new Date().getTime()) {
}
}
let b = 0;
let normalWeek = (hour === 6 || hour === 10) && (day > 0 && day < 6);
while (b === 0) {
console.log('Testing Started...');
if (normalWeek === true) {
b++;
goodSignal();
sleep(10000);
continue;
}
if (normalWeek === false) {
b++;
badSignal();
sleep(10000);
continue;
}
}
Aucun commentaire:
Enregistrer un commentaire