Skip to content

Instantly share code, notes, and snippets.

@OlukaDenis
Created August 17, 2019 16:52
Show Gist options
  • Save OlukaDenis/d480e5a1d671db828e03eaa96e7a0d59 to your computer and use it in GitHub Desktop.
Save OlukaDenis/d480e5a1d671db828e03eaa96e7a0d59 to your computer and use it in GitHub Desktop.
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