Code down. It accepts a two-digit positive number and removes the difference between the larger and lower numbers. Please help me make the code short.



  •     const a = +prompt('enter a positive two-digit integer');
            if (a < 100 && a > 10) {
              const b = String(a).split('').map(i=>Number(i));
              if(+b[0]>+b[1]){
                console.log(+(b[0]-b[1]));
              }else if (+b[0]<+b[1]){
                console.log(+(b[1]-b[0]));
              }else(
                console.log('the numbers are equal')
              );
              
            } else(
              console.log('enter a positive two-digit integer'));
    


  • We're going to use a string of user input. Under the terms of the target, the length of the line is 2, the line may be converted into a positive whole.

    const number = prompt("Enter a positive two-digit integer");
    if (!(c=Number(number)) || c%1 || c<0 || number.length != 2) console.log("Введите положительное двузначное число");
    else console.log((r=Math.abs((n = number.split(""))[0]-n[1]))==0?"Числа равны":r);


Log in to reply
 

Suggested Topics

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