Question

In: Computer Science

HTML 7.20 A palindrome is a number or a text phrase that reads the same backward...

HTML

7.20

A palindrome is a number or a text phrase that reads the same backward and forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a script that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an alert dialog indicating the problem to the user. Allow the user to enter a new value after dismissing the alert dialog. [Hint: It’s possible to do this exercise with the techniques learned in this chapter. You’ll need to use both division and remainder operations to “pick off” each digit.]

Solutions

Expert Solution

Palindrome.html:

   <!DOCTYPE html>
   <html>
   <head>
       <meta charset="UTF-8">
       <title>Five Digit Palindrome</title>
       <script type="text/javascript">
           function Palindrome()
           {
               var start = prompt("Please enter a 5 digit string to check whether it is palindrome or not: ",""); //Get the inputted String
               var palindrome = new Array(); //Empty array to write the diffferent palindrome data to..
              
               while(start.length !=5) //create a loop for checking reelating to the length
               {
                   alert("You didn't enter a 5 digit string! Please enter a 5 digit string!!");
                   start = prompt("Please enter a 5 digit string to check whether it is palindrome or not: ",""); // Ask the user to re-enter the value again
               } //end while
              
               for(var i=0; i<=start.length-1 ;i++){ //loop to pull off and isolate individual characters
                   palindrome[i] = start.charAt(i); //Add each character to a new array
               };
              
               //Note that i did not check whether the numbers were numeric...I just checked whether strings are matched or not...!
               if(palindrome[0] == palindrome[4])
               {
                   //check whether first digit equals to the fifth digit.
                   if(palindrome[1] == palindrome[3]) //check whether second digit equals to the fourth digit.
                   {
                       document.write("The number you entered is:"+start+".");
                       document.write("<br> The number "+start+" is a palindrome");
                   }
               }
               else //if 1 does not equals to 5 and 2 doesn't equals to 4, then the string is not a palindrome!
               {
                   document.write("The number you entered is:"+start+".");
                   document.write("<br> The number "+start+" is not a palindrome");
               };
              
           };   //end of main function  
       </script>      
   </head>
   <body onload="Palindrome()">
       <h1> Palindrome Finder!</h1>
   </body>
   </html>

Output:


Related Solutions

A palindrome is a word or phrase, which reads the same backward or forward. Write a...
A palindrome is a word or phrase, which reads the same backward or forward. Write a program that prompts the user for a string of characters terminated by a period and determines whether the string (without the period) is a palindrome. IMP: Assume that the input contains only letters and blanks. Assume also that the input is at most 30 characters long. Use an array of characters of size 30 to store the input! Disregard blanks when deciding if the...
A palindrome is a string that reads the same forward and backward, i.e., the letters are...
A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right.      Examples: radar à is a palindrome Able was I ere I saw Elba à is a palindrome good à not a palindrome Write a java program to read a line of text and tell if the line is a palindrome. Use a stack to read each non-blank character...
A palindrome is a word or a phrase that is the same when read both forward and backward.
6.7 LAB: PalindromeA palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.Ex: If the input is:bobthe output is:bob is a palindromeEx: If the input is:bobbythe output is:bobby is not a palindromeHint: Start by removing spaces. Then check if a string is equivalent to it's reverse.This is my code:s =...
(Palindrome number - A number is a palindrome if it reads the same from right to...
(Palindrome number - A number is a palindrome if it reads the same from right to left and from left to right, for example 676 is a palindrome number) Write a program that prompts the user to enter a three-digit integer number and determines whether it is a palindrome number or not In Java Please
JAVA Palindrome Detector A palindrome is any word, phrase, or sentence that reads the same forward...
JAVA Palindrome Detector A palindrome is any word, phrase, or sentence that reads the same forward or backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a boolean method that users recursion to determine where a String argument is a palindrome. The method should return true if the argument reads the same forward and backward. Demonstrate the method in a program. Include the following...
Foundation of Computer Science A palindrome is a string that reads the same forward and backward....
Foundation of Computer Science A palindrome is a string that reads the same forward and backward. 1. Describe an algorithm that determines whether a string of n characters is a palindrome. 2. Write its corresponding program using your favorite programming language.
In Java A palindrome is a word or sequence of characters which reads the same backward...
In Java A palindrome is a word or sequence of characters which reads the same backward and forward, such as madam, dad, racecar, 5885. In java Write a program that asks user to enter a word and prints if the word is a palindrome or not.
A palindrome is a string that reads the same forward and backward, for example, radar, toot,...
A palindrome is a string that reads the same forward and backward, for example, radar, toot, and madam. Your task is to construct a python algorithm to receive as input a string of characters and check whether it is a palindrome using a stack and a queue. Your ADTs contains the following methods: Queue Queue() – constructor enqueue(e) – enqueue an element dequeue(e) – dequeue an element len() – returns the number of elements in the queue Stack Stack() -...
JAVA. A palindrome is a word or a phrase that is the same when read both forward and backward.
java please. A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.Ex: If the input is:bobthe output is:bob is a palindromeEx: If the input is:bobbythe output is:bobby is not a palindromeHint: Start by removing spaces. Then check if a string is equivalent to it's reverse.Hint: Start by just handling single-word...
4.A palindrome is a nonempty string over some alphabet that reads the same forward and backward....
4.A palindrome is a nonempty string over some alphabet that reads the same forward and backward. Examples of palindromes are all strings of length 1, civic, racecar, abba,… Give a DP algorithm to find the longest palindrome that is a subsequence of a given input string. What is the running time of your algorithm? (40 points). •Examples: •Given the input “character”, your algorithm should return “carac”. •Given the input “TTATGTGAT”, your algorithm should return “TATGTAT” Python Code only
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT