0

how do you code a palindrome program in JavaScript?

a program to check if a word is the same when reversed

8th May 2020, 9:36 PM
Ebuka Victor
Ebuka Victor - avatar
3 Answers
+ 4
function isPalindrome(word){ return word==word.split("").reverse().join(""); } alert(isPalindrome("mom")) //output true
8th May 2020, 9:52 PM
CoffeeByte
CoffeeByte - avatar
+ 1
ok thanks, so I tweaked your code to get the result I wanted... //palindrome checker function palindrome(word){ var word = prompt("enter word"); if( word.split("").reverse().join("") == word){ alert(" a palindrome"); } else{ alert("not a palindrome"); } } palindrome() //check if the word is same when reversed
8th May 2020, 10:06 PM
Ebuka Victor
Ebuka Victor - avatar
0
You reverse the string with Array.prototype.reverse() and compare the two strings.
8th May 2020, 9:40 PM
Alessandro Palazzolo
Alessandro Palazzolo - avatar