Advertisement
PowerCell46

Sum and multiplication JS

Nov 13th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumAndMultiplication(input) {
  2.  
  3. let inputedNumber = Number(input[0]);
  4. let stringNumber = inputedNumber + "";
  5. let numberOfDigits = (stringNumber.length);
  6. let finishingNumber = null;
  7. finishingNumber = stringNumber[numberOfDigits - 1];
  8. finishingNumber = Number(finishingNumber);
  9. let result = null;
  10. let theNumberIsFound = false;
  11. let theResultIsPrinted = false;
  12.  
  13. for(let a = 1; a <= 9; a++) {
  14.  
  15.     if(theNumberIsFound === true) {
  16.     break;
  17. }
  18. for(let b = 9; b >= a; b--) {
  19.  
  20.     if(theNumberIsFound === true) {
  21.     break;
  22. }
  23. for(let c = 0; c <= 9; c++) {
  24.  
  25.     if(theNumberIsFound === true) {
  26.     break;
  27. }
  28. for(let d = 9; d >= c; d--) {
  29.  
  30. if((a + b + c + d) === (a * b * c * d) && finishingNumber === 5) {
  31.  
  32. console.log(a + "" + b + "" + c + "" + d);
  33. theResultIsPrinted = true;
  34. theNumberIsFound = true;
  35. break;
  36. }
  37.  
  38. result = ((a * b * c * d) / (a + b + c + d));
  39. if(Math.trunc(result) === 3 && inputedNumber % 3 === 0) {
  40. console.log(d + "" + c + "" + b + "" + a);
  41. theResultIsPrinted = true;
  42. theNumberIsFound = true;
  43. break;
  44. }
  45.  
  46. }
  47. }
  48. }
  49. }
  50.  
  51. if(theResultIsPrinted === false) {
  52. console.log('Nothing found');
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement