Ask coding questions

← Back to all posts
How do I display the follower count thats retrieved in the JS file as an HTML elements text?
aflacc

In the attached repl, I have a .js file that gets my Scratch Follower count. It works, because it prints the count in the console, but in the index.html file, there's an <a> element with the id="follow", which I want to have the text in it be set to the output that the .js thing gets. Does this make sense?

Answered by flafflar [earned 5 cycles]
View Answer
Voters
lightsowner
aflacc
Comments
hotnewtop
flafflar

You never define the variable followers, and that's why nothing is displayed.

aflacc

how can i then? I am new to API stuff. @wulv

flafflar

@aflacc Well, first, since the fetch function is asynchronous, you should put all your code related to the request inside the then clause.

Also, another error in your code is that x.text() is also async, which means that you have to do something like this:

So, in conclusion, your code should look like this:

SixBeeps

Just take whatever's being logged and set the followers variable to that value.

aflacc

but hOW @SixBeeps