Mixed Messages finished product - plus, long template literals

Hi all! Find my finished project here: (there is also a link to run the code online!)
GitHub - chrysippa/new-greek-myths: Random message generator for myths.
It generates ‘New Greek Myths’ - stories with elements taken from real myths, and involving randomized characters and places. Some of the randomized elements sound out of place in a myth, just to make it fun :slight_smile:

I thought the project was pretty easy. It did take up a couple days of my spare time, but that’s mostly because I had way too much fun coming up with the story templates and digging around for names to use.

I did run into one problem and I’m wondering if anyone else has dealt with it too. Since I was adding random elements into an otherwise pre-written story, I opted to use a template literal string. Instead of leaving the stories as one line of super long text that runs off the screen, I wrapped them at about 80 characters per line, but when you wrap a template literal, there appears to be no way to keep it indented at the same level as the rest of the code. If you do indent, that indentation becomes part of your string, because… template literals take you literally. A quick Google search didn’t come up with any good solutions, except maybe concatenating short segments together, and not only would that look kind of ugly (in my opinion) it would also be labor-intensive if I want to update the stories and the line lengths change.

What do you guys think? Did you also have long strings, and handle them differently? Should I try concatenation because indentation is important for readability? I’m tempted to leave it as is… but it looks gross :sob:

Hi Chrysippa,

Just saw you’ve also completed the task. The code looks good to me from my beginner’s point of view :smiley:

In my case I wanted to print every single message on a new line, so I’ve stored the final messages as an array. In the end I’ve used array.join("\n") which would format the array as a string and print every message on a new line ("\n" inside the join method worked in console. For HTML I had to changes it to array.join("<br>"). I’m not sure if that’s the best option for when you combine with html but it does the job for now).

So you basically just need to add \n instead of \ where you want to have a new line.
I made a quick test on my laptop and it worked in console.

Let me know if that worked for you.

Atanas

PS: I’ve just realised that you wanted to avoid changing the position of where the line appears if you make future updates. Can’t think of anything that would sort that automatically at the moment :roll_eyes:

I did note that technique in your code. Given that this isn’t a project I’ll be updating much, I might just switch to it and accept that it isn’t completely ideal.

Thanks for your feedback!