Tell us what’s happening:
no se porque cuando toco check me salta el alert de una y no corre el codigo, no se que tengo mal configurado, alguien me puede guiar??
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset = 'UTF-8'>
<title>Palindrome Checker</title>
</head>
<body>
<div class="container">
<input id="text-input">
<button id="check-btn">Check</button>
</div>
<div id="result"></div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
/* file: script.js */
const textInput = document.getElementById('text-input').value;
const check = document.getElementById('check-btn');
const result = document.getElementById('result');
function isPalindrome(str) {
let cleanStr = str.toLowerCase().replace(/[^A-Za-z0-9]/gi, '');
let checkedStr = cleanStr.split('').reverse().join('');
let resultMsg = `${str} ${cleanStr === checkedStr ? 'is' : 'is not'} a palindrome`
return resultMsg;
}
const checkPalindrome = (str) => {
if (textInput == "") {
alert('ingrese una palabra o frase');
return;
}
let cleanStr = str.toLowerCase().replace(/[^A-Za-z0-9]/gi, '');
let checkedStr = cleanStr.split('').reverse().join('');
let resultMsg = `${str} ${cleanStr === checkedStr ? 'is' : 'is not'} a palindrome`
const pTag = document.createElement('p');
pTag.className = 'user-input';
pTag.innerHTML = resultMsg;
result.appendChild(pTag);
result.classList.remove('hidden');
}
check.addEventListener('click', () => {
checkPalindrome(textInput.value);
textInput.value = "";
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker