-
Notifications
You must be signed in to change notification settings - Fork 0
20240905 FizzBuzz問題 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
01.fizzbuzz/fizzbuzz.js
Outdated
output += "Buzz"; | ||
} | ||
if (output === "") { | ||
output = i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
他の行では output
に string が格納されますが、この行では output
に number が格納されます。特定の変数にはある 1 つのデータ型のデータを格納する方がよいので、そうしてくださいー。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cafedomancer
かしこまりました。変数展開を使用してoutput
に入るデータ型を文字列に統一しました。
if (output === '') {
output = `${i}`;
}
01.fizzbuzz/fizzbuzz.js
Outdated
output += "Buzz"; | ||
} | ||
if (output === "") { | ||
output = `${i}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number を string に変換したいのであれば別の方法を使ってください。テンプレート文字列は、文字列中に変数を埋め込むための仕組みだからです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テンプレート文字列は、文字列中に変数を埋め込むための仕組みだからです。
かしこまりました。以後、テンプレート文字列を使用する際は今回のように単体で使用するのではなく、文字列の中で必要な際に使用するようにします。
toString
メソッドを使用して実装するようにしました。
if (output === "") {
output = i.toString();
}
@cafedomancer |
プラクティス
FizzBuzz問題(JavaScript)
FizzBuzz実行結果
フォーマット
下記2コマンドで整形
参考記事
等価演算子と厳密等価演算子の違い