Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

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

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

回溯法(Backtracking)& 分支定界法(Branch and Bound)

回溯法(Backtracking)& 分支定界法(Branch and Bound)

How to solve the perpetual loading issue in Evernote? Evernote 一直轉圈圈的解決辦法

How to solve the perpetual loading issue in Evernote? Evernote 一直轉圈圈的解決辦法

如何成為專家 - 心態篇(用心讓學習變好玩)

如何成為專家 - 心態篇(用心讓學習變好玩)


Comments