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:trueorfalse, never the string"true". Strict equality is exact, so"Delivery"and"delivery "don’t match"delivery", and the string"7"doesn’t match the number7. - Run code only when the answer is yes with an
ifstatement. 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,messageholds the current record itself. - Count matches by starting with
let count = 0;once, before the loop, runningcount = 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 istrueonly when both checks are.