Code 101: Reverse and Palindrome Checker This is an old code I found in my college notebook. This program reverses the string/number and determines whether it is a palindrome or not. Even special characters will be checked and recognized too. 1. Reverse - to go backward or in the opposite direction. (last to first) Example: MyHero = oreHyM 2. Palindrome - any words, numbers or phrase that reads the same backward or forward. Example: Top Spot = topspot This is a topic covered in our Web Development course. It takes me some time to analyze and run the program. Well, Coding/Making a program is trial and error learning. Heres's the code - Just a test Live Demo: https://codepen.io/mihsaky/pen/QWvYvYJ *Use the latest version of Jquery HTML <html> <body> <h3>Palindrome and Reverse Checker</h3> <!--Input box --> Enter String or Number : <input class="form-control" id="stringnum" placeholder="" type="text" required> <!-- Submit Button -> <button id="palrevcheck">Check</button> <h4 id="answer">Result:</h4> <!-- The Result Box --> <div id="palrevresult" style="text-align:justify; color:#666; background-color: #eee; border: 1px solid #999; padding: 15px; overflow-y:scroll; height:130px;"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> </body> </html> Javascript $(document).ready(function() { //Reverse and Palindrome Checker $('#palrevcheck').on('click', function() { var stringnum = $("#stringnum").val(); var lowRegStr = stringnum.toLowerCase().replace(/\s+/g, ''); var reverseStr = lowRegStr.split('').reverse().join(''); if (!stringnum) { $('#palrevresult').html('<b>You need to input a string or number</b>'); } else { if (reverseStr !== lowRegStr) $('#palrevresult').html('<div><b>Reverse String/Number: </b><br>' + reverseStr + '</div> <br><b>Palindrome Checker:</b><br><span style="color:#F00; font-weight:bold;">' + lowRegStr + '</span> is not a Palindrome'); else $('#palrevresult').html('<div><b>Reverse String/Number: </b><br>' + reverseStr + '</div> <br><b>Palindrome Checker:</b><br><span style="color:#F00; font-weight:bold;">' + stringnum + '</span> is a Palindrome of <span style="color:#F00; font-weight:bold;">' + lowRegStr + '</span>'); } }); //Reverse and Palindrome Checker }); #Programming
Log in to join in Reading is open to everyone. Replying needs an account.
1 comment
What languange did you use to programming, it is vb.net?