Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://shpp.gitbook.io/zero/tutorials/loops/triangles
- let n = +prompt('Введіть розмір сторони трикутника');
- //1 triangel
- let i = 0;
- while (i < n) {
- let star = "";
- i++;
- let j = 0;
- while (j < i) {
- star += "*";
- j++;
- }
- console.log(star);
- }
- console.log();
- //2 triangel
- i = 0;
- while (i < n) {
- let j = n, star = "";
- while (j > i) {
- star += "*";
- j--;
- }
- i++;
- console.log(star);
- }
- console.log();
- //3 triangel
- i = 0;
- while (i < n) {
- let space = "";
- let j = 0;
- while (j < i) {
- j++;
- space += " ";
- }
- let star = "";
- j = n;
- while (j > i) {
- j--;
- star += "*";
- }
- console.log(space + star);
- i++;
- }
- console.log();
- //4 triangel
- i = 0;
- while (i < n) {
- i++;
- let star = "", j = 0;
- while (j < i) {
- j++;
- star += "*";
- }
- let space = "";
- j = n;
- while (j > i) {
- j--;
- space += " ";
- }
- console.log(space + star);
- }
Advertisement
Add Comment
Please, Sign In to add comment