Code0Em / lingua-sonnet

A web application to search word definitions, pronunciations and usage in poetry
MIT License
0 stars 1 forks source link

JS for Poetry API (checks random poem for user’s word) #18

Closed Code0Em closed 9 months ago

Code0Em commented 9 months ago

JS: Created a function which checks if the random poem (from the API) contains the user’s word. If it does, the poem is displayed on the page. If it doesn’t, another random poem is generated up to a maximum of ten times. After which, error message is displayed.

HTML: Added id to generate poem button (for grab in function above).

STILL TO DO: Grab the user's word from the input field and incorporate it into above function.

Code0Em commented 9 months ago

JS for “getting” user’s word

JS: [1] Created a function (with an event listener) which "gets" the user's word, when they enter a word and selects the save button. Within this, use an if/else statement to validate the user’s input and display an error message if the input’s blank.

[2] Created another function (with an event listener) which resets the fetch function count, when the user selects the generate poem button (so that new random poems can be generated/in case on the first round, no random button is found with the user's word).

[3] Update existing functions so user’s word is “pulled” into these.

HTML: Added a Save Word button, and an p element (for error/confirmation message).