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

[Linux] Vmmem 記憶體佔用過高(wsl, ubuntu)

[Linux] Vmmem 記憶體佔用過高(wsl, ubuntu)

《鳥哥 Linux 私房菜:基礎篇》Chapter 02 - 主機規劃與磁碟分割

《鳥哥 Linux 私房菜:基礎篇》Chapter 02 - 主機規劃與磁碟分割

[Week6] 給自己看的 HTML 基礎

[Week6] 給自己看的 HTML 基礎


Comments