3
0

下から順に。。。

面倒くさいので画面パタメータをListでもらった後のFunctionだけ

ちなみに引数のListを作ってる箇所はこっちの記事に書いてあるYO!!

square.js
// [問題文(原文)]
// 整数 N が入力されるので、N 個の*を繋げた文字列を出力するプログラムを作成しましょう。
// 例えば N = 3の場合
// ***
// のように出力してください。
function square(lines) {
  if (!Array.isArray(lines) || lines.length !== 1) {
    console.log("1行入れろや!");
    return;
  }
  const repCnt = Number(lines[0]);
  if (!Number.isInteger(repCnt) || repCnt < 0 || repCnt > 100) {
    console.log("1~100の整数入れろや!");
    return;
  }
  console.log('*'.repeat(repCnt));
}

module.exports = {
  square
};

repeat関数を使えば、forを書かなくてもスグに同じ文字の連結ができちゃうね。
"給料上げて!".repeat(∞)

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0