Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJon Buckley
5,573 PointsBummer: Your code took too long to run
I've entered the following code for one of the nested object challenges in JavaScript but it keeps showing the "your code took too long to run" error. It's not causing a loop and the code looks right to me. I've also removed the key/value pairs and it throws a different error so it's working up to a point. Any suggestions?
const objects = [ { car: "ford", car: "ferrari" }, { tool: "hammer", tool: "saw" } ];
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Jon,
I’m not sure what particular challenge this is for, but a single object shouldn’t have a duplicate key. So if car is a key, then within the same object you can’t have another car property because then when you call objects[0][‘car’] how would JavaScript know which value to give back to you. It could send back ‘ford’ or ‘ferrari’.
Same thing with the tool key in the second object.
Try correcting that and see if that helps you pass your challenge.
Jon Buckley
5,573 PointsJon Buckley
5,573 PointsHi Brandon,
Of course, silly me! Thanks for pointing this out.