Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice forEach in JavaScript!
You have completed Practice forEach in JavaScript!
Preview
Let's walkthrough the solution to the seventh code challenge.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
For the last challenge, we need to use
the forEach method to capitalize all
0:00
the strings in the months array and store
them in the array named capitalizedMonths.
0:04
To start, I'll copy and paste the code
into Atom to make it easier to read.
0:10
I started my solution to this
challenge like all of the others,
0:19
by stubbing out the call to the for
each method.
0:22
So months.forEach.
0:25
I used month,
the current value parameter name,
0:29
followed by a fat arrow and
a set of curly braces.
0:33
To get the capitalized month,
I called the string to uppercase method,
0:37
to convert the month text
into uppercase letters.
0:41
So, first our variable const,
0:45
capitalizedMonth=month.toUppercase.
0:47
Then I pushed the capitalize month
onto the capitalizedMonths array,
0:58
capitalizedMonths.push(capitalizedMonth).
1:03
And that's the solution.
1:08
And just like we did before,
we could also eliminate this code block.
1:10
To do that, we would cut this code and
1:17
place it inside of the call
to the push method.
1:20
That allows us to eliminate
this intermediate variable and
1:24
the curly braces.
1:28
And that's it!
1:31
Nice job sticking with it and completing
all of the code challenges in this course.
1:33
Thanks for practicing array
iteration methods with me.
1:38
Be sure to rate the challenges or
videos in this course, and
1:41
let us know your feedback.
1:44
We'll see you next time.
1:46
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up