Random Quote Machine

https://www.reddit.com/r/learnprogramming/comments/4bzz4a/htmlcssjavascript_using_an_api_to_get_random/

HTML

<input type="text" id="apikey" placeholder="Mashape API Key" />
<button id="getQuote">
  Random Quote
</button>
<p>

</p>

CSS

#apikey{
  width:80%;
}

JavaScript

$('#getQuote').click(function() {
  var apiKey = $('#apikey').val();
  if (apiKey) {
    $.ajax({
        type: "POST",
        beforeSend: function(request) {
          request.setRequestHeader("X-Mashape-Key", apiKey);
        },
        url: "https://andruxnet-random-famous-quotes.p.mashape.com/",
        dataType: 'json'
      })
      .done(function(data) {
        $('p').text(data.quote);
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        alert("Request failed: " + errorThrown);
      });
  } else {
    alert("Please provide API key");
  }
});