iracheredn1chenko

Задача. Трикутники. while

Sep 23rd, 2021 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Ira Cherednichenko
  2. //https://zero.p2p.shpp.me/tasks/3_4_triangle.html
  3. //while
  4.  
  5. //1
  6. let squareSize = +prompt("Вкажіть розмір трикутника");
  7. let squareText1 = "";
  8. let i = 0;
  9. while (i < squareSize) {
  10.     i++;
  11.     let j = 0;
  12.     while (j < i) {
  13.         j++;
  14.         squareText1 += "*";
  15.     }
  16.     squareText1 += "\n";
  17. }
  18. console.log(squareText1);
  19.  
  20. //2
  21. let squareSize1 = +prompt("Вкажіть розмір трикутника");
  22. let squareText1 = "";
  23. let i = 0;
  24. while (i < squareSize1) {
  25.     i++;
  26.     let j = squareSize1;
  27.     while (j >= i) {
  28.         j--;
  29.         squareText1 += "*";
  30.     }
  31.     squareText1 += "\n";
  32. }
  33. console.log(squareText1);
  34.  
  35. //3
  36. let squareSize2 = +prompt("Вкажіть розмір трикутника");
  37. let squareText2 = "";
  38. let i = 0;
  39. while (i < squareSize2) {
  40.     i++;
  41.     let j = squareSize2;
  42.     while (j > i) {
  43.         j--;
  44.         if (i >= 0) {
  45.             squareText2 += " ";
  46.         }
  47.     }
  48.     let k = 0;
  49.     while (k < i) {
  50.         k++;
  51.         squareText2 += "*";
  52.     }
  53.     squareText2 += "\n";
  54. }
  55. console.log(squareText2);
  56.  
  57.  
  58. //4
  59. let squareSize3 = +prompt("Вкажіть розмір трикутника");
  60. let squareText3 = "";
  61. let i = 0;
  62. while (i < squareSize3) {
  63.     i++;
  64.     let j = 0;
  65.     while (j <= i) {
  66.         j++;
  67.         if (i > 0) {
  68.             squareText3 += " ";
  69.         }
  70.     }
  71.     let k = squareSize3;
  72.     while (k >= i) {
  73.         k--;
  74.         squareText3 += "*";
  75.     }
  76.     squareText3 += "\n";
  77. }
  78. console.log(squareText3);
Advertisement
Add Comment
Please, Sign In to add comment