Skip to content
Exit presentation

Data Handling II: Databases & Structured Data

Two conditions, both true

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.

Jump to lesson

This track

  1. 0 Start here
  2. 1 One record, one row
  3. 2 The naming value
  4. 3 Naming the columns
  5. 4 Asking the register one question
  6. 5 Two conditions, both true
  7. 6 The answer, in order
  8. 7 Counting the groups in the answer
  9. 8 What a database adds
  10. 9 The big picture
  11. 10 Track quiz

Other tracks