JSFiddle - React, Tailwind, and code Playground

by jiggle

JavaScript

function createCheckDigit(membershipId) {
  // Write the code that goes here.
  
  var chars = membershipId.split('');
  
  var checkDigit=0;
  while(chars.length>1){
    console.log('chars > 1');
    chars.forEach(char=>
    {
      console.log(char)
      checkDigit+=parseInt(char);
    });
    if (checkDigit.toString().length>1){
       chars = checkDigit.toString().split('');
      console.log('length > 1' + chars.length)
    }
    else
      {
        chars=""
      }
    console.log('checkDigit:' + checkDigit);
  }
  return checkDigit;
}

console.log(createCheckDigit("55555"));