0

The goal is to check a URL or Cookie for the given set of values, and if not found; move to the If Else statement where language is verified. Everything works fine when the initial IF statement is removed. However, when like this; the else if is not reached

if (["ccov", "top10", "cenf", "aip", "constructioncoverage", "seniorliving", "aginginplace", "seniorlist"].some((value) => ref1.includes(value)) || ["ccov", "top10", "cenf", "aip"].some((value2) => getcookie('track-page-1').includes(value2))) {
  s1.src = 'https://embed.tawk.to/620675459bd1f31184dc28c0/1frkjk5mj';
} else if (userLang.match(/^en/)) {
  s1.src = 'https://embed.tawk.to/60a7b623b1d5182476bb3457/1f67huun6';
}

It is likely I have a misunderstanding of some.(value). Then again, the IF statement is working perfectly.. However the else if is never engaged when IF is false

I have tried changing "else if" to just "if" and it still does not work

Tanner T
  • 25
  • 5
  • 2
    **However the else if is never engaged when IF is false** Obviously the `if` is never false. Which means your `if` condition is not what you intended. – Barmar Feb 11 '22 at 22:49
  • Why is the 'If' statement never false in this scenario? Thanks for the assistance – Tanner T Feb 11 '22 at 22:50
  • 3
    Because if it were false you would go to the `else if`. – Barmar Feb 11 '22 at 22:51
  • Well of course; but I am trying to understand what in particular is causing it to always be true.... – Tanner T Feb 11 '22 at 22:51
  • 2
    What are the values of `ref1`, `getcookie('track-page-1')`, and `userLang` when it's not working as you expect? – Barmar Feb 11 '22 at 22:51
  • 1
    The `if` will be true if either `ref1` contains one of the strings in the first array, or the cookie contains one of the strings in the second array. It doesn't have to be both conditions. – Barmar Feb 11 '22 at 22:53
  • 1
    If you want both conditions to be matched, use `&&`, not `||`. – Barmar Feb 11 '22 at 22:53
  • Either condition is fine, I meant to use || – Tanner T Feb 11 '22 at 22:54
  • 2
    Then answer my question: What are the values of the variables when it's not working correctly? – Barmar Feb 11 '22 at 22:56
  • 2
    [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) and [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173) – VLAZ Feb 11 '22 at 23:01
  • 2
    BTW, you can use `userLang.startsWith('en')` instead of a regexp. – Barmar Feb 11 '22 at 23:05

0 Answers0