Palindrome with js
PALINDROME WITH JS
VIDEO LINK: https://youtu.be/t9-wqbzvATE?si=7QkvRMDnImKZNRx1
What is palindrome in first place?
-> a word,phrase,or sequence that reads the same backwards as forwards.eg: madam
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello World</h1>
<input type="text" class="input">
<button class="btn">Click me</button>
</body>
<script src="palindrome.js"></script>
</html>
JAVASCRIPT CODE:
btn = document.querySelector('.btn');
btn.addEventListener("click" , ()=>{
input = document.querySelector('.input');
a = input.value;
b = a.split('').join();
c = a.split('').reverse().join();
input.value = '';
if(b==c){
console.log("Yes it is a Palindrome");
}
else{
console.log("No the given string is not a palindrome");
}
})
Comments
Post a Comment