Select Page
I realized this morning that I need the displayPoem function to have both the selectedAuthor and the selectedTitle parameters to pick the correct poem. Since lots of poem titles have been used more than once.
At first I thought selectAuthor would be stored in list.addEventListener
And I could just pass both selectedAuthor and selectedTitle from list.addEventListener when the user clicked on a title.
But that didn’t work. 
So I was trying to think of some way to pass selectedAuthor down to displayPoem, but I couldn’t find a way
Then I thought I could just make selectedAuthor a global variable and set it initially to an empty string and let it be written over.
I used let at first, since I thought the variable needed to change.
But it didn’t work.
So then I tried const just to see; didn’t work.
Then I tried also putting let selectedAuthor in the list.addEventListener (instead of const); didn’t work
Then I left that in place and tried to again pass both the selectedAuthor and the selectedTitle from the event listener to the displayPoem function; didn’t work.
See below screenshot 
It’s always the same. The console was asked to log out the poem and that’s undefined.
To check if the selectedAuthor is making it to the displayPoem function, I also asked the console to log both the selectedAuthor and the selectedTitle — it logs only the selectedTitle, suggesting to me that the selectedAuthor variable is never getting to the displayPoem function.

poem pick screen shot with console

So what now?

On Monday 7/25: 

working on the displayPoem function. Trying to figure out how to get only the exact requested poem to print. The issue is that I search by title and many poems have the same title. Planning on looping through each poem and confirming that the author name matches selectedAuthor. Using indexOf, slice, split, the word “author” and the new line character (\n) to isolate the author’s name. Have not yet figured out how to avoid accidentally choosing the text after the word ‘author’ in a poem title. Unfortunately, I cannot seem to make the author section appear before the title section in the output. I also had to change the format from json to text because things like poem.lines (to get at the lines in the api) were coming back undefined even though the json file is structured like lines: [line are here].

On Tuesday 7/26:

Completed the poemDisplay section. Used split and the index numbers to select the author name and title; used the author name in an if-then to confirm we have the correct author (for when different authors have written poems with the same title); used splice and join with the break tags to print the poem in the correct format.