Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 5 of 11

Two conditions, both true

Show on a big screen

8 min

Text size

Two conditions must both say yes. The steps below call each condition a door. A row must pass both doors.

Five rows, the same five as before.
Step 1 of 4
  1. Five rows, the same five as before.
  2. First door: section is 9-A.
  3. Second door: due at least 1000.
  4. Only one of these five passes both.

The rule

Two conditions joined by and keep a row only when both hold. Two conditions keep fewer rows, or the same — never more.

Here sectionAt and dueAt hold the section and due positions. The sign >= means is at least. One if sits inside the other. So a row is added only after passing both.

  1. const sectionAt = headers.indexOf('section');
  2. const dueAt = headers.indexOf('due');
  3. if (row[sectionAt] === '9-A') {
  4. if (row[dueAt] >= 1000) {
  5. answer.push(row);
  6. }
  7. }

Every kept row also passed the first condition. So the second one cannot add rows.

On the full register, this keeps 4 of the 12 records. They are A-101, A-106, A-108 and A-110.

Ask for due at least 0, and all 7 of 9-A pass. Every due is at least 0. That is the same count, not fewer.

Pick a section and slide the due below. Read who passes both.

Loading lab…

Fewer or the same — a second condition never adds a row.

Try the lab to finish this lesson.