Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

Please tell me why not a single test passes except 1-4. Although everything works for me in the preview tab when I enter test lines by hand.

Your code so far

/* file: script.js */
const checkBtn = document.getElementById('check-btn');

const input = document.getElementById('text-input');

const result = document.getElementById('result');

let value = ''

input.addEventListener('input', (e) => {value = e.currentTarget.value})

const checkPalidrome = (str) => {
if (!str.length) {
  alert('Please input a value')
  } else {    
    const replacedStr = str.replace(/\W/g,'').replace(/_/g,'').toLowerCase()     
    const reversedStr = replacedStr.split('').reverse().join('')
    if (replacedStr === reversedStr) {
    result.innerHTML = str + ' is a palindrome'
    } else {
      result.innerHTML = str + ' is not a palindrome'
    }
  }
}

checkBtn.addEventListener('click', () => {checkPalidrome(value)})


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 OPR/106.0.0.0

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

I didn’t look at the tests but it is likely just because of how it is tested.

If you remove the event listener from the input element and don’t pass an argument to the checkPalidrome function but instead just get the value from input.value inside the function your code should pass.

Thank you. you’d be right.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.