1

The ugly code underneath represents the problem I'm facing. How to properly implement the situation, where 1 and 2 is displayed unconditionally, whilst 3 only after the certain condition is met.

function one() {
    console.log('1');
    console.log('2');
    two();
    console.log('3');
}

function two() {    
    while (true) {
        if (document.cookie.indexOf('SOMECOOKIE=') != -1) {            
            break;
        } 
    }
}
Mike
  • 11
  • 2
  • 2
    So you learn how to use promises and you need to have something watch the cookie for it to change. The best thing would be if something on the clientside is changing the cookie, it would fire a custom event. – epascarello Dec 14 '17 at 14:14
  • the topic is about "delaying" the execution of a function not about reading cookies – messerbill Dec 14 '17 at 14:17
  • 1
    A promise won't help with implementing a delay either (although it could be used to make the code more maintainable once there is a solution) – Quentin Dec 14 '17 at 14:18

0 Answers0