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

JSDC 2020 開發者年會參與心得分享

JSDC 2020 開發者年會參與心得分享

React 基礎:Props Drilling 和 useContext

React 基礎:Props Drilling 和 useContext

筆記、GIT 超新手入門 - "Branch"

筆記、GIT 超新手入門 - "Branch"


Comments