-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex2.js
32 lines (24 loc) · 866 Bytes
/
ex2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function load(){
palindrome2();
}
function palindrome(){
let word = prompt("Please enter a word");
let revWord = word.split("").reverse().join("");
word === revWord? alert("It is a palindrome word") : alert("It is not a palindrome word");
}
// Solution 1
function palindrome1(){
const word = prompt("Please enter a word");
const revWord = word.split("").reverse().join("");
word === revWord? alert("It is a palindrome word") : alert("It is not a palindrome word");
}
// Solution 1
function palindrome2(){
const word = prompt("Please enter a word");
let isPalindrome = word.split("").every((letter, i) => {
let otherSideIndex = i + 1;
return letter === word[word.length - otherSideIndex];
})
isPalindrome? alert("It is a palindrome word") : alert("It is not a palindrome word");
console.log(2)
}