Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda