<labelclass="label"for="text">Enter your text below.</label> <textareaclass="textarea"id="text"></textarea>
<p>You've written <strong><spanid="word-count">0</span> words</strong> and <strong><spanid="character-count">0</span> characters</strong>.</p>
=======
HTML
1 2 3 4 5 6 7 8 9 10 11
<p>Show some random quote.</p>
<divclass="quote-container"> <blockquotearia-live="polite"> <spanclass="quote-mark">“</span><spanclass="quote-output">Waiting for a new quote...</span> </blockquote> </div>
/* As the user types or pastes content in, the text of the #word-count and #character-count elements should be updated to show how many words and characters are in the #text field. */
/* When the page loads, a random quote from the Ron Swanson Quotes API should be displayed in the blockquote element. When the More Ron button is clicked, a new quote from the API should replace the current one. */
/* Modify any methods that you can to support chaining. Ideally, the methods to add and remove classes should be chainable.*/
const $ = (function () {
// Create Constructor function here const Constructor = function (selector) { this.elements = document.querySelectorAll(selector); };
// Immutable copy of the matching elements Constructor.prototype.items = function () { returnArray.prototype.slice.call(this.elements); };
// Get first item Constructor.prototype.first = function () { returnthis.elements[0]; }
// Get last item Constructor.prototype.last = function () { returnthis.elements[this.elements.length - 1]; }
// Add class to element Constructor.prototype.addClass = function (newClass) { this.items().forEach(element => { element.classList.add(newClass); }) returnthis; };
// Remove class from element Constructor.prototype.removeClass = function (newClass) { this.items().forEach(element => { element.classList.remove(newClass); }) returnthis; };
return Constructor; })();
// Create new instance const btns = new $('.button')
// Check the console logs in dev tools console.log('$.items()', btns.items()); console.log('$.first()', btns.first()); console.log('$.last()', btns.last());
// Add and remove class btns.addClass('btn-purple').removeClass('btn-blue');