#dogTin render issue

7 messages · Page 1 of 1 (latest)

patent crag
olive spoke
#

It basically all boils down to this line:

let newDog = dogs[dogsArray.shift()]

As an additional hint, add console.log(doge); as the first thing you do in your render() function to see what your doge variable points to when you render.

rancid mist
#

You have problem with the following line:
let newDog = dogs[dogsArray.shift()]

  1. .shift() take out the first element of the array and returns it.
  2. Your data is stored inside dogs not dogsArray
  3. The following line will give you an error once you depleted your dogs array: return newDog ? new Dog(newDog) : {}
    I would recommend returning null instead of an empty object, then check against that value and render something else out if you don't have more data left
patent crag
#

Okay so I changed my code to:
const newDog = dogs.shift()

which now works but for some reason not on the first click which is very strange to me. Do you guys know why?

patent crag
olive spoke
#

put your code inside triple back-ticks

#

and it does work the first time but you're not taking into account that you initially display the first dog but don't remove it from the list so when you click you get the first dog AGAIN and display it...