0
while (studentRecords.readNextRecord()) {
    currentZipCode       =  studentRecords.getStudentZipCode();
    currentGender        =  studentRecords.getStudentGender();

    if (currentZipCode === FIRST_ZIPCODE) {
        if (currentGender === "M")
        document.write("53711: Males: " + currentGender + "<br />");
    }
}

How can I add all the M's together to produce 53711: Males: 5??

1
  • are you asking for how to count all record having currentGender == M then display it? Commented Nov 21, 2015 at 18:41

1 Answer 1

1

Keep a running count, and don't output the total until you're done with the loop.

var males = 0;

while (studentRecords.readNextRecord()) {
  currentZipCode       =  studentRecords.getStudentZipCode();
  currentGender        =  studentRecords.getStudentGender();

  if (currentZipCode === FIRST_ZIPCODE) {
    if (currentGender === "M") {
      ++males;
    }
  }
}

document.write("53711: Males: " + males + "<br />");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.