-
Notifications
You must be signed in to change notification settings - Fork 130
feat(m1): add solution exercise 024 completed #3010
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
56ad8d3
9057b29
0366f8b
262510e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function playFizzBuzz(){ | ||
let phrases = ''; | ||
|
||
const length = 100; | ||
|
||
for (let i = 1; i <= length; i++) { | ||
let phrase = i; | ||
|
||
if ( i % 3 === 0 ){ | ||
phrase = 'fizz'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hint: |
||
} else if ( i % 5 === 0){ | ||
phrase = 'buzz'; | ||
} else if ( i % 3 === 0 && i % 5 === 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this code ever run? ;-) |
||
phrase = 'fizz and buzz'; | ||
|
||
} | ||
|
||
phrases += i === length ? phrase : phrase + '\n'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is also not recommended. |
||
} | ||
|
||
return phrases; | ||
} | ||
|
||
function init(){ | ||
console.log( playFizzBuzz() ); | ||
return; | ||
} | ||
init(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, I advise not to complicate the solution and to solve it with at most three conditions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I made the changes for all comments, thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This algorithm does not solve the problem correctly. |
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.
The use of this additional variable
phrase
is not recommended.