Error using Fetch

When using fetch to request data from The Movie DB I got stuck on this google inspect panel console error.
I don’t know what to do because I passed the API KEY correctly.
If anyone can help I would be grateful :slight_smile:

exercise link below:
URL: https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-22-async-javascript-and-http-requests/modules/wdcp-22-learn-javascript-syntax-requests/projects/js-film-finder

const tmdbKey = ‘###’;
const tmdbBaseUrl = ‘https://api.themoviedb.org/3’;
const playBtn = document.getElementById(“playBtn”);

const getGenres = async () => {
const genreRequestEndpoint = “/genre/movie/list”;
const requestParams = “?api_key=tmdbKey”;
const urlToFetch = tmdbBaseUrl + genreRequestEndpoint + requestParams;

try {
const response = await fetch(urlToFetch , {cache: ‘no-cache’});
if (response.ok) {
const jsonResponse = await response.json();
console.log(jsonResponse);
}
} catch (Error) {
console.log(Error);
}
};

Hi there. It looks like the problem is here:

const requestParams = “?api_key=tmdbKey”;

You are not handling concatenation correctly. tmbdKey is the name of your variable and not its value.
The correct way would be:

const requestParams = "?api_key=" + tmdbKey;
//or
const requestParams = `?api_key=${tmdbKey}`;
2 Likes

Thank you very much, I didn’t notice.
:slight_smile:

1 Like