Hello everybody
I just finished this project. You can review it here:
https://github.com/iam-davidvm/CP_MixedMessages/blob/main/mixedmessage.js
My own thoughts:
- I’m not sure if I fully understood the challenge, but the program will render a random message based on 4 arrays: artist, verb, song and adverb. It runs smoothly so that’s OK.
- Besides coding the program, I really tried to embrace the GIT way of working. init, add, commit, push are clear to me. I didn’t use any branches or return to a previous commit. Maybe next time.
- I added some features:
- A user could input non random values. Maybe he wants random sentences about Eminem only.
- A user can add items to an array of choice
- A user can delete items of an array of choice.
Most of my time I spent on searching a planner tool (not needed for this exercise) and searching for input of the arrays.
Regards
David
1 Like
I created a pull request to your project with my code revision. I think it makes it easier to read. Interested in hearing your thoughts.
Hello Alan
Thank you for your feedback. A function will make the code cleaner indeed.
I saw your feedback on GitHub in my inbox. I am going to implement it first without looking at your solution. I think it will be better for my learning curve. Afterwards I will look at your solution and see where I can even improve.
Have a nice day
Also the createSentence function with custom options is pretty un-useable the way it is written if you only wanted to update one value. Consider having a default option specified for each value that way if a person gave the command
createSentence(customSong='happy birthday')
that one value would persist in the call but you wouldn’t need to specify a value for the other 3 arguments. You’ll need to refactor your if statements also after making this change.
Hi Alan
Thanks for the extra feedback. About the default option. I was going to implement this at first, but I noticed it worked without adding the default option. Is adding the default option more an agreement of ‘good programming’.
What I tried to achieve in my code is a user can input:
createSentence(‘Billy Joel’, ‘performed’, ‘Piano man’,‘on a guitar’);
but also
createSentence(‘Billy Joel’, false, ‘Piano man’, false)
If I would implement your suggestion, how does this affect the arguments? With my current knowledge, I would think I still have to use false to achieve the same result?
My code hasn’t changed yet. I will probably do this tomorrow.
Actually never mind on the default value for the function. I’ve been doing to much python recently and I guess javascript works different.
but this was more along the lines of what I was thinking. I like the pass an object solution instead of args from here
https://www.markhansen.co.nz/javascript-optional-parameters/
1 Like
Thank you for your reply. I just found this link: https://careerkarma.com/blog/javascript-default-parameters/ where a function is used as a default. I think I can implement this in my code.