Created
August 17, 2019 16:52
-
-
Save OlukaDenis/d480e5a1d671db828e03eaa96e7a0d59 to your computer and use it in GitHub Desktop.
Checking for a palindrome using Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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