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?