Stuck again 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.
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
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
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!