Select and Count Feedback (Summary)

This course started with a teammate’s question: “How many messages about returns came in, and which ones are they?” You saw early on that a number alone isn’t worth much. Someone will ask which messages you counted and why one made the cut while another didn’t.

Now you can answer those questions. Well done making it to the end! Here’s what you can write and explain after this course, and where the path goes next.

What You Can Write Now

You can write logic that selects the right messages and counts them, keeping the messages behind the answer. Step by step, that means you can:

  • Ask one message a yes-or-no question with === or !== and store the answer as a Boolean: true or false, never the string "true". Strict equality is exact, so "Delivery" and "delivery " don’t match "delivery", and the string "7" doesn’t match the number 7.
  • Run code only when the answer is yes with an if statement. The braces decide what belongs to the block, and code after the closing brace runs either way.
  • Visit each message with for (const message of messages). The block runs once for each message, in order, and zero times for an empty list. On every pass, message holds the current record itself.
  • Count matches by starting with let count = 0; once, before the loop, running count = count + 1; only for a match, and using the count after the loop.
  • Keep the messages behind the count by starting const selected = []; before the loop and pushing each whole matching message. The selected list keeps the original records, IDs and all, and its length is your count.
  • Combine two requirements by storing two checks and joining them with &&, which is true only when both checks are.

What You Built

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.