Check for the presence of an element with indexOf() already solved but have a question

Check for the presence of an element with indexOf() already solved but have a question
0

#1

I have the following code below which is passing but when I console.log it I see all the false statements but not the true ones. Is my solution correct? Why is the console.log not showing which ones are returning true?

function quickCheck(arr, elem) {
  //console.log("arr:", arr);
  //console.log("elem:", elem);
  //console.log('-----end of array----')
  // change code below this line
  if (arr.indexOf(elem) > -1) {
    return true ;
  } else { 
    return false;
  }
  // change code above this line
}

// change code here to test different cases:
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));

#2

Can you add a link to the exercise and format your code?

You can hit preformatted text in your editor to format your code.


#3

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

Note: Backticks are not single quotes.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.