Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

379
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!