Pumpkin patch - JS recursion/objects

Hello fellow coders,
I was on hacker rank doing some questions and I came to this one, pumpkin picker. I think I did a good job with my code, but the count isn’t working. I modified the code a few times and I’m unsure of what I’m missing. Maybe it’s the recursion.
Anyway, here’s the work I’ve done. Any guidance would be appreciated, even with formatting. Thanks!

let pumpkinPatch ={
  meadow: {
    byTheRock: 'apples',
    byThePuddle: 'pumpkin'
  },
  hill: {
    byTheBench: {
      leftOfBench: 'pumpkin',
      rightOfBench: 'pumpkin'
      }
    },
    topOfHill: 'apples'
};


//count how many pumpkins there are 
function pumpkinPicker(location){
  // variable pumpkin to compare
  let pumpkin = 'pumpkin';
  //counter variable to keep counter
  let count = 0;
  //cycling through object
    for (let key in location){
      let area = location[key]
      //console.log(area, typeof area)
        if (typeof area === 'object'){
        // console.log(area)
          let subArea = pumpkinPicker(area)
            if (subArea === pumpkin){
              count++
            }
        }else{
            if (area === pumpkin){
              count++
            }
        }
      
    }
  return count
}

answer should be 3, what outputs is 0

It’s difficult to help without knowing what’s passed to the function, can you give an example for how the location parameter is structured?

I’m sorry! I thought I included said object. I just edited the post to include it, thanks

the function returns count, a number, this is not doing what you want

subArea is never equal to pumpkin

add also console.log(subArea)

Hey,

I figure since the recursion is taking the object and trying to get its values that what I need to keep count of is area. However, the answer still doesn’t compute correctly if i just do this

for (let key in location){
      let area = location[key]
      //console.log(area, typeof area)
        if (typeof area === 'object'){
          let subArea = pumpkinPicker(area)
         //console.log(subArea)
          if(subArea){count++}
        }else{
            if (area === pumpkin){
              count++
            }
            //console.log(count)
        }
      //console.log(count)
    }

I also tried

  for (let key in location){
      let area = location[key]
      //console.log(area, typeof area)
        if (typeof area === 'object'){
          let subArea = pumpkinPicker(area)
        }else{
            if (area === pumpkin){
              count++
            }
            //console.log(count)
        }
      //console.log(count)
    }

I suggest two approaches:

take pen and paper, and write down step by step what the algorithm should do, and only after you have a working algorithm, translate it to code

look at your code using a tool like http://pythontutor.com/javascript.html

Hey. I figured it out, I was doing my if else statement wrong.
That website you sent me is a cool tool. Thanks for all your help.