text: // Copyright 2019 Google LLC
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     https://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  /**
   * Fetches a random quote from the server and adds it to the DOM.
   */
  function getRandomQuote() {
    const responsePromise = fetch('/random-quote');
    responsePromise.then(handleResponse);
  }
  
  /**
   * Handles response by converting it to text and passing the result to
   * addQuoteToDom().
   */
  function handleResponse(response) {
    const textPromise = response.text();
    textPromise.then(addQuoteToDom);
  }
  
  /** Adds a random quote to the DOM. */
  function addQuoteToDom(quote) {
    const quoteContainer = document.getElementById('quote-container');
    quoteContainer.innerText = quote;
  }
  
  /**
   * The above code is organized to show each individual step, but we can use an
   * ES6 feature called arrow functions to shorten the code. This function
   * combines all of the above code into a single Promise chain. You can use
   * whichever syntax makes the most sense to you.
   */
  function getRandomQuoteUsingArrowFunctions() {
    fetch('/random-quote').then(response => response.text()).then((quote) => {
      document.getElementById('quote-container').innerText = quote;
    });
  }
  
  /**
   * Another way to use fetch is by using the async and await keywords. This
   * allows you to use the return values directly instead of going through
   * Promises.
   */
  async function getRandomQuoteUsingAsyncAwait() {
    const response = await fetch('/random-quote');
    const quote = await response.text();
    document.getElementById('quote-container').innerText = quote;
  }
  