Receipt of a three-digit number from the keyboard and remove the sum of the number



  • // How to achieve the objective by means of methods .reduce / or .map ?

     const a = +prompt('enter a positive tree-digit integer');
     if (a < 1000 && a > 100) {
      const b = String(a).split('');   // дальше этой строки не получается
      console.log(b)
    } else(
      console.log('enter a three-digit positive number')
    


  • const a = 123;
    const b = String(a).split('').map(i => Number(i)).reduce((r, i) => r + i);
    console.log(a, b);


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2