Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

378
Visualizações
I'm following a tutorial and get an uncaught Syntax error in promise while the code in the video works just fine, Please look into it

I'm a learner on currently following a YouTube tutorial on JS, And the below code worked fine in the video, but I get an error message

error: Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Console log shows the line which has the code console.log("finished!"); as the line with the error

The JS code:

const getDataFromForm = () => {
  const requestObj = {
    firstName: "Humaid",
    lastName: "Ahamed",
    categories: ["nerdy"],
  };
  return requestObj;
};

const buildRequestUrl = (requestData) => {
  `http://api.icndb.com/jokes/random?firstName=${requestData.firstName}&lastName=${requestData.lastName}&limitTo=${requestData.categories}`;
};

const requestJokeAnotherMethod = async (url) => {
  const Response = await fetch(url);
  const jsonResponse = await Response.json();
  const joke = jsonResponse.value.joke;
  postJokeToPage(joke);
};

const postJokeToPage = (joke) => {
  console.log(joke);
};

const processJokeRequest = async () => {
  const requestData = getDataFromForm();
  const requestUrl = buildRequestUrl(requestData);
  await requestJokeAnotherMethod(requestUrl);
  console.log("finished!");
};

processJokeRequest();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I've notice that I've forgot to return the Chuck Norris API link, Now the code works like charm, Thank you for that person that pointed out my mistake

I had previously not included the return statement in the below function:

const buildRequestUrl = (requestData) => {
  return `http://api.icndb.com/jokes/random?firstName=${requestData.firstName}&lastName=${requestData.lastName}&limitTo=${requestData.categories}`;
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda