Trouble following instructions for XHR Post Requests III


XHR Post Requests III

I am having trouble following the instructions for the above exercise:

Inside the code block of shortenUrl() save this code to a const called urlWithKey:

url + ‘?key=’ + apiKey;

This code includes your API key at the end of the URL.

Here is the entire code; not all of it is relevant to this instruction (i.e., I dont know which block fo code I need to insert this instruction into)

// Include data for accessing Google APIs

const apiKey = 'I. AIzaSyB2sfWuybVQXFLw3x7YEq1HsIse6YR55Gw';
const url = '';

// Some page elements

const $inputField = $('#input');
const $expandButton = $('#expand');
const $shortenButton = $('#shorten');
const $responseField = $('#responseField');

// AJAX functions

function expandUrl() {
  const urlToExpand = url + 
        '?key=' + apiKey +
        '&shortUrl=' + $inputField.val();
  const xhr = new XMLHttpRequest(); 
  xhr.responseType = 'json';
  xhr.onreadystatechange = function() {
    if (xhr.readyState === XMLHttpRequest.DONE) {
      $responseField.append('<p>Your expanded url is: </p><p>' + xhr.response.longUrl + '</p>');
  };'GET', urlToExpand);

function shortenUrl() {
url + '?key=' + apiKey;

function expand() {
  return false;

function shorten() {
  return false;

// Call functions on submit



Any help will be greatly appreciated


Instructions: Inside the code block of shortenUrl() save this code to a const called urlWithKey


For some reason it worked now and didn’t work before.

Your code was technically wrong; this is what I had to put in the block:

const urlWithKey = url + '?key=' + apiKey


Man, you need to focus. I just quoted your code.

Good that you found the answer by yourself. I’m just not sure this was worth a topic.

You could have just looked at expandUrl() btw.


what do you mean? what do you mean?


No, I ain’t doing this. Figure it out.


I get it after looking around. Thanks for the input!