JSFiddle - React, Tailwind, and code Playground

Jeremy Beagle-Palindrome

by David Lomneck

HTML

<!--don't edit this file-->

<div id=question>
<span style="font-weight:bold">Question 2:</span> A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest
  palindrome larger than K to output. Numbers are always displayed without leading zeros.
  <P>
    Example:
    <br/> Number Given: 808
    <br/> Output: 818
    <br/> Number Given: 2133
    <br/> Output: 2222
    <br/>
  </P>
</div>
<br/>
<p>Your Results:</p>
<div id="results2"></div>

CSS

p {
  padding: 0px 0px 0px 15px;
}

#question {
  border: 1px solid gray;
}

div {
  padding: 15px 15px 15px 15px;
  border: 1px solid blue;
}

JavaScript

// You may use: https://developer.mozilla.org if you need help with syntax
// https://getfirebug.com/firebug-lite-debug.js as external resource for a build-in console window
function Q2(number1) {
  var returnValue = "";
  var counter = 0;
  var palindromeFound = false;
  while (palindromeFound === false && counter < 1000) {
    number1++;
    console.log(`Tested Value: ${number1}`);
    palindromeFound = isPalindrome(number1);
    counter++;
  }
  returnValue = number1;
  return returnValue;
}

function isPalindrome(value) {
  let string = value.toString();
  let characterArray = string.split('');
  for (let i = 0, j = characterArray.length - 1; i < j; i++, j--) {
    if (characterArray[i] !== characterArray[j]) {
      return false;
    }
  }
  return true;
}


$("#results2").append(Q2(556));