Today’s page builds upon yesterday’s Word Count. A haiku is a poem comprised of 5, 7, and 5 syllables on three lines. Clicking on the flower will give you all the details!
I used .keyup() to show the user’s poem and syllable count below the input box as they type. I split the text using spaces to create an array. I then went through the words and counted the number of syllables in each word and updated a total syllable count.
As the syllable count is updated, the text is added to the corresponding div and line. If the total syllable count is less than or equal to 5 syllables, the string is added to the first line. If it is more than 5 but less than or equal to 12, it is added to the second line. The total syllable count for line 3 is more than 12 but less than or equal to 17. If the total syllable count is greater than 17, the words are not added to the analysis display.
Have fun writing!
Day 25 – Write a Haiku