Assessment help - JSON

Hi guys,

Stuck again :frowning: I’ve been working on the JSON assessment for a while but I’m lost. I think the problem probably has to do with scope and I’m not sure how to rectify the situation. I appreciate the code will only work in the live window but I’ve linked to my CodePen to share my work so far.

CodePen

Regards,

Jared

Hey Jared,

This exercise will leave you breathless. I had a read over the code and i have to say the way you tried to tackle it is novel. I think your problem is with your for-loops.

Iterating over nested objects is like itterating over nested arrays, the pattern goes

let obj = {Property : Value, 
           nestedProperty:{
                 subProperty : value
               }
            }
//Outer Loop-Parent Level
for(let p(arent) = 0 ;  p < obj.length ; p++){
  anything you want to do to the parent you do here: 
 //Child Loop
  for(let c = 0; c < obj.nestedProperty.length < c++){
  //Any logic you want to prefrom on the child

Take a look at mine, I hope it might help…
Js Fiddle

Keep up the good work man,

Hello @Jared_Cave

hope that everything going fine with you

as @drgaud said there issue in the for loop
this for (let i = 0; i === catObject.length; i++)
will make the loop not even run single time cause at first i will equal 0 then you test if it equal to the catObject length which will always be false unless the catObject is empty which is not the case here

hope that help and have a nice day both of you :slight_smile:

Thanks! That’s a sloppy mistake. In theory, I guess I could have used ‘!==’ ? But there’s no need since ‘<’ will do.

Thanks for a really clear and helpful explanation. I’ve just completed the assessment. Admittley is this took me some time because I made a few syntax errors but besides that, after your help, it was pretty staight forward!

Hope you’re enjoying your weekend.

Regards,

Jared

you welcome @Jared_Cave if you used !== it will work

have a nice day

Thanks again.

You too :+1:t5:

you welcome and thanks :slight_smile: