Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I'm struggling with this code. I need to Save a text entry doing the following: // ...get the textarea element's current value // ...make a
I'm struggling with this code.
I need to Save a text entry doing the following:
// ...get the textarea element's current value // ...make a text item using the value // ...store the item in local storage using the given key
and then to Connect the saveEntry event listener to the textarea element 'change' event.
The existing variables and functions have already been given to me. Code lines I need to add are at the bottom of the code. Please see below
function addTextEntry(itemKey, initialText, isNewEntry) { // Make textarea element to edit the entry var textElement = document.createElement("textarea"); textElement.rows = 5; textElement.placeholder = "(new entry)"; // Set the textarea's value to the given text (if any) textElement.value = initialText; // Add a section to the page containing the textarea addSection(itemKey, textElement); // If this is a new entry (added by the user clicking a button) // move the focus to the textarea to encourage typing if (isNewEntry) { textElement.focus(); } // Make event listener to save the entry when it changes // (i.e. when the user types into the textarea) function saveEntry() { // A new version of this function is created every time addTextEntry is called, // so it can access all the variables available in this call to addTextEntry console.log("saveEntry called with variables in scope:", { itemKey, initialText, isNewEntry, textElement, }); // Save the text entry: // ...get the textarea element's current value // ...make a text item using the value // ...store the item in local storage using the given key } // Connect the saveEntry event listener to the textarea element 'change' event }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To save the text entry when the textarea element changes and connect the saveEntry event listener to ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started