Function problems

Function problems
0.0 0

#1

Tell us what’s happening:
the code is shows an error !
it says that str.forEach() is not a function. I dont understand that

Your code so far

function palindrome(str) {
  // Good luck!
   var a="";
  str=str.toLowerCase();
  var letterNumber = /^[0-9a-zA-Z]/;
 str.forEach(function(inputtxt) {
  if(inputtxt.value.match(letterNumber)){
   a.push(inputtxt);
  }  
 });
  a.replace(" ","");
  var b=a.split("");
  b=b.reverse();
  b=b.join('');
  
  return a.equals(b);
}  
palindrome("eye");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36.

Link to the challenge:


#2

Because there is no forEach() functon provided for strings

If you want to loop over the individual characters in a string, you can use split('') (split at empty, creating an array of single character strings) and then use forEach on that.

To turn an array of single char strings into a string again, you can call join('') (join array elements with an empty string between them) at the end