Using JavaScript how can call two functions at the same time? I need these functions to be called if an Id is inside a variable

I am trying to call two functions “company1Qualified()” & “company2Qualified()” if the corresponding id is in bookable companies variable. My issue is that I can not call both functions at the same time with my condition. Only one function will get called at the moment. The first id in bookableCompanies will always be called but it fails to call both functions. What is causing this? How can I get this to call both functions when the ids are in bookableCompaines?

I created a test environment below to run this code. Thanks!

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test setQualified</title>
</head>
<body>
<h1>Test setQualified</h1>
<button onclick="setQualified()">setQualified</button>
</body>
<script>
function company1Qualified() {
console.log("Call company1Qualified");
}
function company2Qualified() {
console.log("Call company2Qualified");
}
function setQualified() {
const company1Id = "0011U00002LNeJ9QAL";
const company2Id = "0011U00002BkHdaQAF";
let iscompany1Q = "";
let iscompany2Q = "";
// let iscompany1Q = company1Qualified();
// let iscompany2Q = company2Qualified();
// Get List of Bookable Companies.
let bookableCompanies =
"0011U00002LNeJ9QAL, 0011U00002BkHdaQAF, a1FKi000000PBG8MAO, 0011U00002GhNOXQA3";
var companiesArray = bookableCompanies.split(",");
// Check if company1Id and company2Id are in bookableCompanies
if (
companiesArray.includes(company1Id) &&
companiesArray.includes(company2Id)
) {
iscompany1Q = company1Qualified();
iscompany2Q = company2Qualified();
} else if (companiesArray.includes(company2Id)) {
iscompany2Q = company2Qualified();
} else if (companiesArray.includes(company1Id)) {
iscompany1Q = company1Qualified();
}
const qualifiedCompanyValue =
iscompany2Q && iscompany1Q
? `${company1Id}, ${company2Id}`
: iscompany2Q
? company2Id
: iscompany1Q
? company1Id
: "";
console.log("Qualified Companies:", qualifiedCompanyValue);
}
</script>
</html>
</code>
<code> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Test setQualified</title> </head> <body> <h1>Test setQualified</h1> <button onclick="setQualified()">setQualified</button> </body> <script> function company1Qualified() { console.log("Call company1Qualified"); } function company2Qualified() { console.log("Call company2Qualified"); } function setQualified() { const company1Id = "0011U00002LNeJ9QAL"; const company2Id = "0011U00002BkHdaQAF"; let iscompany1Q = ""; let iscompany2Q = ""; // let iscompany1Q = company1Qualified(); // let iscompany2Q = company2Qualified(); // Get List of Bookable Companies. let bookableCompanies = "0011U00002LNeJ9QAL, 0011U00002BkHdaQAF, a1FKi000000PBG8MAO, 0011U00002GhNOXQA3"; var companiesArray = bookableCompanies.split(","); // Check if company1Id and company2Id are in bookableCompanies if ( companiesArray.includes(company1Id) && companiesArray.includes(company2Id) ) { iscompany1Q = company1Qualified(); iscompany2Q = company2Qualified(); } else if (companiesArray.includes(company2Id)) { iscompany2Q = company2Qualified(); } else if (companiesArray.includes(company1Id)) { iscompany1Q = company1Qualified(); } const qualifiedCompanyValue = iscompany2Q && iscompany1Q ? `${company1Id}, ${company2Id}` : iscompany2Q ? company2Id : iscompany1Q ? company1Id : ""; console.log("Qualified Companies:", qualifiedCompanyValue); } </script> </html> </code>
    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Test setQualified</title>
  </head>
  <body>
    <h1>Test setQualified</h1>

    <button onclick="setQualified()">setQualified</button>
  </body>

  <script>
    function company1Qualified() {
      console.log("Call company1Qualified");
    }

    function company2Qualified() {
      console.log("Call company2Qualified");
    }

    function setQualified() {
      const company1Id = "0011U00002LNeJ9QAL";
      const company2Id = "0011U00002BkHdaQAF";
      let iscompany1Q = "";
      let iscompany2Q = "";
      // let iscompany1Q = company1Qualified();
      // let iscompany2Q = company2Qualified();

      // Get List of Bookable Companies.
      let bookableCompanies =
        "0011U00002LNeJ9QAL, 0011U00002BkHdaQAF, a1FKi000000PBG8MAO, 0011U00002GhNOXQA3";
      var companiesArray = bookableCompanies.split(",");

      // Check if company1Id and company2Id are in bookableCompanies
      if (
        companiesArray.includes(company1Id) &&
        companiesArray.includes(company2Id)
      ) {
        iscompany1Q = company1Qualified();
        iscompany2Q = company2Qualified();
      } else if (companiesArray.includes(company2Id)) {
        iscompany2Q = company2Qualified();
      } else if (companiesArray.includes(company1Id)) {
        iscompany1Q = company1Qualified();
      }

      const qualifiedCompanyValue =
        iscompany2Q && iscompany1Q
          ? `${company1Id}, ${company2Id}`
          : iscompany2Q
          ? company2Id
          : iscompany1Q
          ? company1Id
          : "";

      console.log("Qualified Companies:", qualifiedCompanyValue);
    }
  </script>
</html>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật