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

277
Views
How to print javascript return value without clicking a button?

I want to print the followers in my webpage, it shows up in the console, but not the html document. the code:

async function getFollowers(user) {
      const response = await fetch(`https://scratchdb.lefty.one/v3/user/info/${user}`);
      let responseJson = await response.json();
      const count = document.getElementById.innerHTML("123");
      count = responseJson.statistics.followers;
      return count;}

function pfollows(user) {
   const element = document.getElementById.innerHTML("123");
   const USER = user;
   getFollowers(USER).then(count => {
      element.textContent = `${USER} has ${count} followers right now.`;
   });
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

document.getElementById.innerHTML("123") seems wrong.

You should be passing an id as a string to document.getElementById like document.getElementById("someIdHere"). innerHTML is not a function and shouldn't have parentheses or an argument after it.

count looks like it should be extracted from responseJson and returned.

pfollows looks like it might be responsible for updating the actual DOM.

Redefining user as USER is somewhat redundant.

async function getFollowers(user) {
      const response = await fetch(`https://scratchdb.lefty.one/v3/user/info/${user}`);
      let responseJson = await response.json();
      const count = responseJson.statistics.followers;
      return count;
}

function pfollows(user) {
   const element = document.getElementById("123").innerHTML;
   getFollowers(user).then(count => {
      element.textContent = `${user} has ${count} followers right now.`;
   });
}

When pfollows is called, then the element with id="123" should have its content set to the desired string. If pfollows() is not called, then nothing will happen.

There's a few more possible touchups to clean up:

  • responseJson can probably be a const
  • You can inline return count without saving it to a variable return responseJson.statistics.followers

but trying to keep the changes minimal as needed to fix the problems.

about 4 years ago · Santiago Trujillo 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!