Image

Imagenathanmm wrote in Imagejavascript 😊content

Listens: Elliot -- Son of Sam

Palindrome

Here's the script. Everything works fine (even the effed-up math) except the alerts. I want an alert when the number input is not five-digits. After the alert showing it's not five digits I want it to allow the user to put another number in. Any help would be appreciated.



<SCRIPT LANGUAGE = "JavaScript">

        /* Input a five digit number and verify if it

        is a palindrome. If not: send the user back to

        the start to try again */





var num1, int1

  do {

  num1 = window.prompt("Enter a five digit number", "0");

  int1 = parseInt(num1);}

  while (int1 > 99999 || int1 < 10000)

    if (int1 > 99999 || int1 < 10000)

    window.alert("try again");

    



  val1 = parseInt(num1 / Math.pow(10,4));

  val2 = parseInt((num1 - (val1 * Math.pow(10,4))) / Math.pow(10,3));

  val3 = parseInt((num1 - ((val1 * Math.pow(10,4))) - (val2 * Math.pow(10,3))) / (Math.pow(10,2)));

  val4 = parseInt((num1 - ((val1 * Math.pow(10,4))) - (val2 * Math.pow(10,3)) - (val3 * Math.pow(10,2))) / (10));

  val5 = parseInt((num1 - ((val1 * Math.pow(10,4))) - (val2 * Math.pow(10,3)) - (val3 * Math.pow(10,2))) - (val4 * 10));

  

  

  if ( val1 == val5 && val2 == val4)

    window.alert("You entered a palindromic number!!!!");

    

    



</SCRIPT>