if statement meets multiple conditions but stops at first condition that matches

I am using an if statement and trying to make sure that it stops when it meets most of the conditions that it can. For example if I have the following code:

  const determineLevel = () => {
    const wentToKindergarten = true;
    const wentToElementary = true;
    const wentToHighSchool = true;
    const wentToCollege = false;

    if (wentToKindergarten) {
      return 1;

    if (wentToKindergarten && wentToElementary) {
      return 2;

        if (wentToKindergarten && wentToElementary && wentToHighSchool) {
      return 3;

     if (wentToKindergarten && wentToElementary && wentToHighSchool && wentToCollege) {
      return 4;


In this example, if a student went to kidergarten, elementary, and highschool but skipped out of college, how do I implement this? Right now, it just stops at the first condition it meets. Thanks!

Source: JavaSript – Stack Overflow

November 7, 2021
Category : News
Tags: boolean | conditional-statements | if-statement | javascript | switch-statement

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.