Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Checking for a palindrome using Javascript
function palindromeCheck(){
let word = prompt("Write a word:")
let collection = []
//adding letters from word to collection
for(let i = 0; i < word.length; i++ ){
collection.push(word[i]);
}
this.front = function(){
return collection[0]
};
console.log(collection[0])
for(let i = 0; i < word.length; i++){
rword = rword + collection.pop()
}
console.log("Reversed word: " + rword)
if(rword === word){
console.log(word + " is a palindrome")
} else{
console.log(word + " is not a palindrome")
}
return rword;
}
palindromeCheck()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.