Goal: Practice using
Array.prototype.forEach() to solve the problems below.
Remember, understanding is the goal here. You're absolutely not expected to complete everything listed on this page. In fact, there is often intentionally more content than can reasonably be completed in a single day. (This allows students an opportunity to later review concepts without having to repeat exercises they've previously done). Focus on understanding the concepts, not on speed.
Hint: To do this, build an array of the inputted items. (Make sure you don't include any blank fields.) Sort the array in alphabetical order. Make a new array with each entry uppercased (don't just uppercase them when you display them). Then, display the sorted list of things as list items inside a
Array.prototype.forEach()loop within another
Array.prototype.forEach()loop to build an array representing a deck of cards. A deck consists of 52 cards - 13 ranks in each of 4 suits.
The start of your output should look something like this:
Create a website that lets users input a block of text. The application will then return a list of all the unique words and how many times they appeared.
For example, if the user inputs "hello world world", the page should show:
If you finish, and feel comfortable with
Array.prototype.forEach() loops, try to complete the above exercise but instead order the list by the number of appearances - greatest to least. This is challenging - but a great way to exercise your problem-solving skills.
Further challenge: for words that appear the same amount of times, order by which word appeared first.
Lesson 15 of 38
Last updated March 23, 2021