Return lots of stars


Posted by Christy on 2022-04-19

Description: Write a function named makeStars that accepts a number n and return the star like below.

Note: Don’t use repeat()

makeStars(1) // *

makeStars(2) 

// *
// **

makeStars(5) 

// *
// **
// ***
// ****
// *****

The answers:

function makeStars(n) {
  let star = "";
  for (let i = 1; i <= n; i++) {
    console.log((star += "*"));
  }
  return star;
}

makeStars(5);
function makeStars(n) {
  for (let i = 1; i <= n; i++) {
    let star = "";
    for (let j = 1; j <= i; j++) {
      star += "*";
    }
    console.log(star);
  }
  return makeStars;
}

makeStars(3);









Related Posts

1661. Average Time of Process per Machine

1661. Average Time of Process per Machine

gulp

gulp

專題研討心得:Our brawling love for information technologies in the context of XAI(臺大資管系 畢南怡 助理教授)

專題研討心得:Our brawling love for information technologies in the context of XAI(臺大資管系 畢南怡 助理教授)


Comments