title: Having problems with regex in Javascript
body: <p>I am currently making a senior memory book my English class, and because I'm a nerd I am going to put a bit of code in it. Well, I'm having a bit of trouble with regex in my code.
  My entire code: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//For future reference, "alert(*parametes*)" will make an alert box with the parameters inside it.
  
  //Asks you to enter a phrase and stores your answer.
  var phrase = prompt("Enter a phrase to be checked for palindrome.").toLowerCase()
  //Creates the entered phrase backwards.
  var phraseBackwards = ""
  for (var x in phrase) {
    phraseBackwards += phrase[(phrase.length - 1) - x]
  }
  //Checks to see if the new phrase is a palindrome.
  if (phraseBackwards == phrase) {
    alert("The phrase you entered was a palindrome.")
  }
  //This happens if the preavious condition was false.
  else {
    //Checks if the new phrase is a palindrome without spaces.
    if (phraseBackwards.replace("/\s+/g", '') == phrase) {
      alert("The phrase you entered would have been a palindrome, had it not had spaces")
    } else {
      //Checks to see if the phrase you entered, even without spaces, is not a palindrome.
      if (phraseBackwards.replace(/\s+/g, '') != phrase) {
        alert("The phrase you ented was not a palindrome.")
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The particular portion that is not functioning correctly:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Checks if the new phrase is a palindrome without spaces.
  if (phraseBackwards.replace(/\s+/g, '') == phrase) {
    alert("The phrase you entered would have been a palindrome, had it not had spaces")
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I realize that some of my code may not be optimal but I'm trying to hurry and finish because I procrastinated until last minute.</p>