title: How to check if a generated number already exists
body: <p>This code below creates a random costumer number and prints it out with a simple console log, but one feature is missing: It should check if the same costumer number/ID has already been generated before. If so, it should walk through the process again, so a new random number is generated which then is unique. How can I do that with this code? As a programming newbie I unfortunately have NO clue how I could do that. Maybe a while loop and storing the generated number in a variable? Would be totally awesome if you can provide the code, combined with mine or build in the duplicate-checking feature. </p>
  
  <pre><code>    function generateCostumerNum() {
  
        // generating a random 8-digit number with numbers from 1 to 9
        var zeroToNine = "";
        for (counter = 0; counter &lt;= 7; counter++) {
          var randomNumber = Math.floor(Math.random() * 9) + 1;
          zeroToNine += randomNumber;
        }
  
        // calculating the cross-sum of the generated number above
        var numberforCrossSum = zeroToNine,
          crossSum = 0;
  
        while (numberforCrossSum) {
            crossSum += numberforCrossSum % 10;
            numberforCrossSum = Math.floor(numberforCrossSum / 10);
        }
  
        // building together the final costumer ID string.
        var finalCostumerNum = "ID" + zeroToNine + crossSum;
  
        console.log(finalCostumerNum);
      };
  
      generateCostumerNum();
  </code></pre>