Tell us what’s happening:
The click does not seem to be working but I am unsure as I am unable to console log anything inside the freecodecamp terminal. I seem to get no output at all from the JavaScript. This maybe a stupid question but in my experience I have never had to connect the script.js terminal to the index.html inside freecodecamp, but do I need to do that in the challenges?
I have tested this code on my machine locally and it works perfectly so I am not sure why I am unable to test it at all on here. Any help or advice would be greatly appreciated thank you.
Your code so far
<!-- file: index.html -->
<h1>Is it a Palindrome?</h1>
<input type="text" id="text-input">
<button id="check-btn">Check</button>
<div id="result"></div>
/* file: styles.css */
/* file: script.js */
const button = document.getElementById('check-btn');
const input = document.getElementById('text-input');
const message = document.getElementById('result');
const regex = /^[a-zA-Z]+$/
button.addEventListener('click', () => {
if(regex.test(input.value)){
let value = input.value;
let result = value.split('').reverse().map(letter => letter.toLowerCase());
result.join('');
if(value === result){
message.innerHTML = `${value} is a plandrom`
}else{
message.innerHTML = `${value} is not a plandrom`
}
}else{
if(input.value.length === 0){
message.innerHTML = 'Please input a value'
}else{
message.innerHTML = 'Please input a valid 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
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker