JavaScript Project: Palindrome Checker Issue?

I have a concern with regards to the requirement: When the #text-input element contains the text eye and the #check-btn element is clicked, the #result element should contain the text eye is a palindrome

My code executes this function: (COPY AND PASTE AND SEE FOR YOURSELF)

//Defintions 
const textBox = document.getElementById('text-input')
const checkButton = document.getElementById('check-btn')
const result = document.getElementById('result')

//Functions

const firstUnderscoreRemoval = (text) => {
  const arrayCheck = text.split('')
  if(arrayCheck[0] === '_') {
  arrayCheck.shift()
  } 
  return arrayCheck.join('');
}

const capitalReplacer = (text) => {
  return text.toLowerCase()
}

const cleanInputString = (replacedText) => {
return  replacedText.replace(/[.,-\s_()\/\\]/gi,'');
}


const isPalindrome = (text) => {
  const replacedText = capitalReplacer(text)
  const cleanedText = cleanInputString(replacedText);
  const reversedText = cleanedText.split('').reverse().join('');
  return cleanedText === reversedText
} 

const validateFunction = () => {
if (textBox.value === '') {
alert('Please input a value')
}
}

const masterFunction = () => {
  result.innerHTML = '';
  validateFunction();
  const inputText = textBox.value;
  const presentText = firstUnderscoreRemoval(inputText);
  if (isPalindrome(presentText)) {
    const HTMLString = `<label>${presentText} is a palindrome</label>`;
   result.insertAdjacentHTML('beforeend', HTMLString);}
else {
const HTMLString = `<label>${presentText} is not a palindrome</label>`;
   result.insertAdjacentHTML('beforeend', HTMLString);
}
}

checkButton.addEventListener("click", masterFunction)

Why doesn’t freeCodeCamp recognise my solution?

I’m not sure why you’re wrapped your text in a label? I’d guess that’s confusing the tests

1 Like

I tried switching it to a

element but it didn’t seem to work either?

p element. I meant in ^

Why do you need to add an extra element?

What do you mean? Shouldn’t you always include an element to put in HTML from javaScript.

Sure, but you don’t need to make a brand new element here.

You should have a div element with an id of result

Update the inner text of this element the instructions require. If you don’t put the result where the instructions expect, then the tests can’t find it.