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 trial

JavaScript JavaScript Loops Working with 'for' Loops The Refactor Challenge – Duplicate Code

I had no idea where to put functions

I'm not sure if the loop is inside the function or vis versa but I'm thinking this isn't worth the hassle from previous video all that bother for what is essentially the same result???

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, jasonj7! It may not seem worth it now, but it definitely would be worth it if you had to generate a random RGB for more elements than just the <div>. What if you also wanted a random RGB for the navigation? Or a button? :smiley: Then you could call that over and over and apply it to any number of things. But if you left it confined to that function, then you would have to rewrite essentially the same code in the function that turns a button a random color or a <nav> that turns a random color.

By abstracting out the random RGB, you can use it for an infinite number of things instead of keeping it confined to that one place.

Hope this helps! :sparkles:

Yes your right, I guess I'm a little frustrated with the challenge, as it's the first time I'm using two different functions and a loop within the same program. Up to this point there hasn't been any helpful tutoring on how to incorporate them all.
So I could not complete the challenge and don't know what's going on to be honest.

I'm starting to understand half of the solution, however the complete solution of const randomValue inside randomRGB and randomRGB inside for loop is really hard for me to grasp.

I think in my case individually learning arrow function, function expressions, loops and template literals isn't to bad, but learning how to integrate them all together is where I'm getting stuck. Is there any content or learning on using all these inside a program apart from this challenge video?

I'm really pleased to get this far but I do need help to understand further, anything you could suggest would be really appreciated.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi, jasonj7! I think as you go through the curriculum you'll see it done more and more and more. I feel like it's part of the experience. But I want to take a moment and encourage you to try and think of the things you've been learning: loops, functions, if/else statements, like lego blocks. Yes, that's right... LEGO blocks :smiley:

They can be used anytime, anywhere for anything you like. If I give two kids the same set of lego blocks and no instructions, they're bound to produce different things. One kid may make an airplane and another kid may make a bulldozer. A third kid may just make a mess or some abstract something :smiley: You use what you need, when you need it, to make the thing you're aiming to make.

It would be impossible to teach you every possible combination because they are infinite. My suggestion is to continue along the path and get some experience :smiley:

I understand Jasons feelings. I am having many of the same problems, and it seems with your enthusiasm you seem to have a better clue then him and I. I think what Jason and I are looking for is more tutoring time with a more broader description because there is so much more that you can do with Javascript then whats getting explained in these courses and we are left to figure out a lot with only so much guidance and brain power of our own.

Well its 5 months on since I first attempted this, and just tried again and still can only get half way, my way of thinking is that at the half way point the output is the same as when the challenge is finished... I find as well its not as readable when completed as it was half way through.

My frustration is having this challenge when their are clearly no other lessons bridging the gap from tutorials to challenges, so where does the "get some experience" come from? Would be nice if Treehouse put up more material I don't think that is a unreasonable request. Btw I continued along the path but this challenge is still an outstanding issue.

So where are the extra helpful tutorials because I really need them? If I've missed them could someone please help me locate them on this site.

As it is at the minute I have to do what a moderator from treehouse advised and learn at another site for the information I need, disappointing really considering I will have to probably pay elsewhere.

Hey James! (couldn't tag you for some reason) I understand what you're saying as I greatly struggled with the "assumed" awareness or knowledge of the ability to perform certain tasks with JavaScript at the beginning of my coding journey. However, coding has a great deal to do with logic and it is very important to take a step back sometimes and try to exercise alternatives. For example, I am sure that you aware functions accept arguments, with that being said why not at least TRY to use another function as an argument? It is logically sound that the value of the function being returned can be used as the argument for a different function as an argument just wants a value. Trust me when I tell you I struggled and had many moments where I thought "why was I never taught this!" even outside of Treehouse. Coding is fun, getting frustrated definitely is not! When in doubt, Google it!