Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions projects/m1/024-fizz-buzz/js/index.js
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;

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.


if ( i % 3 === 0 ){
phrase = 'fizz';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hint: phrases += 'fizz' + '\n';

} else if ( i % 5 === 0){
phrase = 'buzz';
} else if ( i % 3 === 0 && i % 5 === 0){

Choose a reason for hiding this comment

The 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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is also not recommended.
It makes no sense to check 100 values ​​to remove the trailing '\n'.
Find a workaround to remove it ;-)

}

return phrases;
}

function init(){
console.log( playFizzBuzz() );
return;
}
init();

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
can you kindly check that everything is ok now and resolve the pr?

Thank you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I made the changes for all comments, thank you.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm does not solve the problem correctly.
But at this point, I suggest you not change the code now.
Write the tests first and see if it really works as you would expect or not.
In short, correct it after testing it ;-)