Function problems

Function problems


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="";
  var letterNumber = /^[0-9a-zA-Z]/;
 str.forEach(function(inputtxt) {
  a.replace(" ","");
  var b=a.split("");
  return a.equals(b);

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:


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