-1

I am teaching myself javascript and still with beginner level. I was wondering how can we get the values of variables 'doodlerBottom' and 'doodlerLeft' at the end of the while loop. This topic has been widely discussed and I have tried many solutions without success..I always get the values doodlerBottom=510 and doodlerLeft=0 while I need the values after the while loop. May somebody help me understand and show me the possible solution. this is a part of the code

function createDoodler(){
    isFirstJump = true 
    isPlaying = false 
    doodlerBottom = 510
    doodlerLeft = 0
    newDoodler = new Doodler(doodlerBottom,doodlerLeft)   
    async function load(){        
        while(doodlerBottom>59){
            doodlerBottom-=2
            doodlerLeft+=1
            newDoodler.doodVisual.style.bottom =`${doodlerBottom}px`     
            newDoodler.doodVisual.style.left = `${doodlerLeft}px` 
            thedoodlerBottom = doodlerBottom
            thedoodlerLeft = doodlerLeft
            await timer(10)  
        } 
    }
    load()
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Mehdi
  • 57
  • 5
  • Mark `createDoodler()` async, then use `await load()` – Barmar Sep 01 '23 at 21:11
  • Barmar is right, but I think use promise to handle async operation, is better. – Coding Ninja Sep 01 '23 at 21:20
  • Thanks Barmar and coding Ninja for your answers, I have marked createDoodler() async and then used await, but then still can't figure out what to do to get the values at the end of the while loop with another function – Mehdi Sep 01 '23 at 21:48

0 Answers0