function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var bbo = 1;
var shbb = 1;
bb.onclick = async function() {
console.log(shbb);
if (shbb=1) {
console.log('while1');
while(bbo>0){
bbo-=0.05;
bb.style.opacity = bbo;
await sleep(1);
if (bbo<=0) {
bbo = 0;
shbb = 0;
bb.style.opacity = bbo;
console.log('while1 - complete');
break;
}
}
}
if (shbb=0) {
console.log('while2');
while(bbo<=1){
bbo+=0.05;
bb.style.opacity = bbo;
await sleep(1);
if (bbo>=1) {
bbo = 1;
shbb = 1;
bb.style.opacity = bbo;
console.log('while2 - complete');
break;
}
}
}
}
Консоль:
1
while1
while1 - complete
0
while1
0
while1
0
while1
Вопрос: почему не доходит до while2? Ведь только он удовлетворяет условиям.