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

筆記:所有的函式都是閉包:談 JS 中的作用域與 Closure

筆記:所有的函式都是閉包:談 JS 中的作用域與 Closure

Day02 : 在 React 中可能會碰到的 JavaScript 觀念

Day02 : 在 React 中可能會碰到的 JavaScript 觀念

【單元測試的藝術】Chap 3: 透過虛設常式解決依賴問題

【單元測試的藝術】Chap 3: 透過虛設常式解決依賴問題


Comments