Seek And Destroy Challenge. Need help with if statement

var answer1=arguments[0];
 var value1=arguments[1];
   var value2=arguments[2];
var finalAnswer=[];

  console.log(answer1);
  console.log(value1);
  console.log(value2);
  
  for (var i=0;i<=answer1.length-1;i++ ){
    if (answer1[i]===value2 || answer1[i]===value1){
      finalAnswer= answer1.splice(i,1);
      finalAnswer.pop();
    }
  
  }
    
         

       console.log(answer1);
       console.log(finalAnswer);

  
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Hi I tried this Seek and Destroy Challenge but my if statement is not working properly. Its not checking for the or option. Its not checking for the comparison of “answer1[i]===value2” option at all.
Any suggestions why?

I know this doesn’t answer your question, but I’ve also had difficulty making || or && work inside if statements, so I’ve just stopped trying. An alternative would be to just do something like:

if (first condition){
code you want}
else if (second condition){
same code as above}

I’m pretty sure the “else if” would prevent the code from running twice if both conditions were true, and otherwise the truth values would work out the same. You can do a fake && by just nesting two if statements as well.

So, that would at least get you by for now, and then maybe later someone who knows what they’re talking about could explain why things are that way.

I tried else if statement already and the result is same. I am new to js so don’t know versatile use of filter() function.

Your if statement is working as intended.

Problem is inside your if statement.

I don’t want to give you direct answer, but as a hint:

  • explain what does .splice()
  • explain what does .pop()

Thanks I tried filter method and it worked. But appreciate it.