*Help Please * Mixed Messages Project

Hey Guys,

I’ve just completed the MM Project but:
1- I’m not sure I really understood the assignment --"
2- The output show the commas from the arrays which is annoying. I’ve used the toString method but the commas are still present.

Here’s the link to my code https://github.com/Phoenix-10010/Mixed-Message.git
Looking forward to get some feedback and help.

Many Thanks.

Phoenix-10010

Regarding commas… From Array.prototype.toString() - JavaScript | MDN (mozilla.org):

For Array objects, the toString method joins the array and returns one string containing each array element separated by commas.

Consider using the Array.prototype.join() function instead. This allows you to specify a separator.

1 Like

Thank you very much.
I’ve now made the change to join method and it worked, no more commas :slight_smile:

When looking at other people’ solutions on the forum, I’ve realised that they’ve created an object to complete this assignment which makes me question whether what I did is conventional ?

At the end of day, it’s the result that matter and not how you did it right ? haha

Thank you again :+1:

Hi,
I have reviewed your code, and I have noticed that your code has a bug that does not impact the functionality of your project. I just wanted to point it out.

The problem in your code is inside your for loop.
let index = Math.floor(Math.random()*i);
This code will never return 2 because Math.random() return between 0 and 1 excluding 1. Your loop stops at 2 therefore Math.random() * 2 will return between 0 and 1.9999999. Then Math.floor() will return between 0 and 1.

As a result, in your switch case, the Case 2: will never be called. I think you should remove it or increase the stopping limit of i to 3.

Like this : for (let i = 0; i <= 3; i++)

1 Like

Hello there !
Thank you very much for your feedback, well spotted !

You actually made me realise that “case 2” was useless because the idea behind the for loop → “for (let i = 0; i <= 2; i++)” was to output 3 different random messages. I then got mixed up in my thought process and created 3 Cases (0, 1 & 2) when actually cases 0 & 1 were enough haha.

I have now removed case 2 from the code.

Thanks again, I really appreciate it :+1: