3-piece fortune teller message generator

Hello everyone! Here is my solution to the portfolio project.

I developed a fortune teller message generator. The program generates a 3-piece message that tells you your lucky number, your fortune, and advice depending on the fortune you got. The fortune piece of the message can vary between good or bad fortune, and the advice also varies on advice for good fortune and advice for bad fortune as well.

It’s implemented as a single object that includes the arrays containing the messages and methods that do the random selection for the final message. The first method gives you a number between 1-100, your lucky number. Next method chooses between good or bad fortune and selects a phrase randomly. The next, based on the previous fortune, selects advice randomly. The last one compiles the messages into a single string and returns the output.

At first, I had some difficulty grasping how to structure the output message, so I checked the example code for that. Then I wanted to add the possibility to get bad fortune, so I added functionality to randomly have it, and get advice accordingly. It took me 2 nights, a couple of hours deciding what to do, how to structure the message, and how to implement it. Next night, it took me a few hours to figure out how to write the methods, debugging, and backing everything up with Git.

Any feedback is more than welcome, as well as any questions!

Best to you all, and happy coding.

1 Like

Hi veehto!

I just downloaded your code and checked it out. That is very clean. Storing all of the data into an object seems smart to me, but I’m not sure if it is “better” to do it this way or not. I essentially created 3 functions that generate their own parts of the message and then I have a 4th function that calls of the other 3 functions like you, but you have all of yours stored into an object. Maybe it is useful to keep those functions as methods of an object instead of just being in the highest domaine (meaning it is a universal function not a method). I really like the use of arrays as your way to store your data as well. I used a case/switch for each function where the case is a random number and it returns a string. I would definitely adopt your array method going forward. Do you have a reason that you stored it all in an object? I would gladly like to hear why, so that maybe I can learn to do it too.

Great Job!
Tyler