"Pseudo"-haiku generator

I decided to write a program that pieced together pseudo-haikus from supplied strings. By “pseudo-haiku”, I am referring only to a short poem that fits the 5-7-5 syllable structure and not accounting for whether the content makes sense.

Writing the program was straightforward and I believe I did it in the most basic way possible. Altogether, it probably took about 45 minutes to get it to the state in which it is currently in. Coming up with the strings for the arrays took more time than I intended, but I think I worried about that part too much.

Overall, I am glad to see that it worked and am interested to see the other users’ implementations.

GitHub repository link

1 Like

Looks neat! One way you could improve further is by remembering the DRY rule (Don’t Repeat Yourself). At the end of your code you have:

console.log(getRandomString(firstFive));
console.log(getRandomString(middleSeven));
console.log(getRandomString(lastFive));

How about writing a second function with a loop that will generate these three console logs? You could also put each array firstFive, middleSeven, and lastFive inside one array:

//Example
let array1 = [1,2];
let array2 = [3,4];
let array = [array1, array2]; // [[1,2],[3,4]]

console.log(array[1][0]);    // logs 3
1 Like

Yeah, I was not satisfied with the repeated lines, but I wanted the output to be three lines. I probably should have looked for a newline character that would have accomplished the same thing that I had with one console.log command.

Thank you for your suggestion.

Hey @secondaidkit,

I really like the concept. Its a bit of fun. You could have packaged it all up in an object and used methods. The structure might have helped you to stay dry.

Something like the randomMenu builder project would have worked as a model.

Still very cool idea

1 Like