0

const arr = ["monday","tuesday","thursday","wednesday",
  "friday","saturday","sunday"];
let newArr = [];
var num = prompt('Enter number :');
for (var i = 0; i < num; i++) {
  var day = prompt('Enter day :');
  if(newArr.includes(day) !== day) newArr.push(day);
}
var num = prompt('Enter number :');
for (var i = 0; i < num; i++) {
  var day = prompt('Enter day :');
  if(newArr.includes(day) != day) newArr.push(day);
}
console.log(7 - (newArr.length));

i only want to know if() part if we entered a repetitive day like friday twice push it once into the newArr for example 1 | friday & 1 | friday ---- > 6

Siavash_Sk
  • 35
  • 5
  • Does this answer your question? [How do I check if an array includes a value in JavaScript?](https://stackoverflow.com/questions/237104/how-do-i-check-if-an-array-includes-a-value-in-javascript) – Nick is tired Dec 14 '21 at 18:15

1 Answers1

1

If you wish to check the entered day is present in the array, and if no, push the element to newArr, change your if condition to:

if(!newArr.includes(day))
{
  ...
}
Deepak
  • 2,660
  • 2
  • 8
  • 23