-5

I set few conditions on if/else but it only working on first condition, I used another way switch and found it completely worked, how do I fixed it?

for (let i = 1; i < 10; i++) {
  let contentall = document.getElementById(`content${i}`)
  contentall.addEventListener('click', (e) => {
        if (xhr.onreadystatechange = okgo) {
          let ibg3 = document.querySelectorAll('.ibg3 img')
          let text2 = document.querySelectorAll('.text2')
          let text4 = document.querySelectorAll('.text4')
          let ibg4 = document.querySelectorAll('.ibg4')
          let arr = [ibg3, ibg4, text2, text4]
          if (e.target !== text2[i - 1] || text4[i - 1] || ibg3[i - 1] || ibg4[i - 1]) {
            console.log("no match")
          } else {
            letgotall(i - 1)
            return
          }

          switch (e.target) {
            case ibg3[i - 1]:
              letgotall(i - 1)
              break;
            case text2[i - 1]:
              letgotall(i - 1)
              break;
            case text4[i - 1]:
              letgotall(i - 1)
              break;
            case ibg4[i - 1]:
              letgotall(i - 1)
              break;
            default:
              console.log("failure")
          }
        }
adiga
  • 34,372
  • 9
  • 61
  • 83
  • 6
    Kindly remove any expletives from your code before posting. Thank you – Alexander van Oostenrijk Dec 24 '19 at 15:13
  • I'm sorry for that, done. – Jhuang Chen Dec 24 '19 at 15:21
  • *Please*, indent your code and use one [indenting style](//en.wikipedia.org/wiki/Indent_style) consistently throughout your code. Doing so makes it **much** easier to read/maintain. As a side effect, doing so for code you place on Stack Overflow makes it much more likely that you will get people to up-vote your posts and makes it more likely that people will put time into Answering your Questions. It doesn't matter which style your choose (although, IMO, some are more appropriate for JavaScript than others). But, pick one and use it consistently for all code in a single project. – Makyen Dec 24 '19 at 15:33
  • Thanks for reminder, I'm wondering why I got so much down-vote, it's my first time knew what's indenting style, thanks again. – Jhuang Chen Dec 25 '19 at 09:21

1 Answers1

-2

Because your condition is wrong, right way is

if(e.target !== text2[i-1] || e.target !== text4[i-1])

or if you don want to repeat e.target you can use

if (!Set(text2[i-1], text4[i-1]).has(e.target)) console.log("Jesus Christ")
Dmitry Reutov
  • 2,995
  • 1
  • 5
  • 20