Jonnie Grieve Digital Media: Website Blog.

Check out my very latest blogs. For more on particular topics check out the post categories.

100 Days of Code: Day 6 Write-up

Project 5 – Using forEach, iterate over the percentages and store all percentages over 50 percent in the array upperRange.

We’ve reached Day 6.  I did try for “Day 6” being the Saturday just gone however numerous things conspired against that. So I wrote most of this write up a few days ago.  It was generally a successfull attempt; barring a couple of quirks I’ve managed to get through both of these JavaScript forEach challenges.

When I started this, I  was either returning an empty array in my console.log or the number 30.

With things still fresh in my mind from previous sessions, I’m testing for values below above 50 in the array and discarding the rest and trying to use the parameter variable to store the results of calculations.

I felt like I was very close but still far away from the answer.

I certainly have the understanding this time of what needs to be done, but implementing it is the tricky part.  I’ve attempted it enough times so let’s see how the solution compares.

This was perfectly acceptable for the challenge.  But inside the code block was the trouble.   I tried to apply thought and the process of elimination to get the answer.   I tried every combination… except the right one.


Since we know we’re calling the forEach method on the percentages array. we don’t need to pass it into push method.  We use the current value parameter for that.

SIX  Using forEach, iterate over the colors array and store the hex colors that start with the letter F (ex. #FF0000) in the array filteredColors.

Again, this challenge is very similar to the previous one. Starting with an array of hexadecimal strings and an empty array for the filtered values to be added to.

Thinking back, I can’t remember too much trouble getting the right answer. Except that for whatever reason, I couldn’t get the console.log to appear in the terminal.  console.log(filteredColors); should return the filtered colours but for no reason that I can see nothing happens. I verified the accuracy of the code having applied it to the code challenge checker.

I’ve even passed it through with 2 alternative answers… a solution that uses the startsWith() method and the other with charAt().

That said, when I bring the code over to a local file on my laptop, it’snot adding anything to the new array even though there’s are no runtime errors in the code.  I’m close, but it’s more than that, I’m seeing a runtime error returned for the first time.  My thought is that it might be a deprecated feature in node.js.  My version of Node is 8.6.0 but in Treehouse Workspaces, it is functional in version 5 of Node.

The final version of my solution uses a shortenecd syntax of the charAt()  method.


Leave a Reply

Your email address will not be published. Required fields are marked *