Hello, this was the program I built for the Mixed Messages projects. Pretty simple, but I guess it works.
1 Like
Hi!
A few tips for future projects:
- Instead of printing the result inside
mixedMessage()
, return the result from it and print it in the main code. This will allow the function to be reused. - Move your constants to the top of the file. Thus, the structure of the code will be as follows: declaration of constants and variables, declaration of functions, main code. It will be easier to read.
- Always specify the code for the
default
branch inswitch
. For example, display an error message withconsole.error
. Then if you add a new category but forget to add a new branch toswitch
, you will get an error and see the problem faster. - You can use nested objects to store your message parts so you don’t need a
switch
:
{
nature: {
items: [...],
actions: [...],
objects: [...],
},
...
}
It may seem more complicated, but with this code it will be easier to add new categories without changing any function’s code.
Good job!