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);