Discuss Scratch

han614698
Scratcher
1000+ posts

More HTML Questions

linearlemur wrote:

han614698 wrote:

linearlemur wrote:

Use this code to display follower count:

<script>
fetch('https://scratchdb.lefty.one/v3/user/info/han614698')
  .then(response => response.json())
  .then(data => followerCount = data["statistics"]["followers"]));
</script>

This sets the “followerCount” variable to the number of followers you have.
That works, but
<p>I have <span id="followerCount">(followerCount)</span> followers</p>
<script>
fetch('https://scratchdb.lefty.one/v3/user/info/han614698')
  .then(response => response.json())
  .then(data => followerCount = data["statistics"]["followers"]));
</script>
just displays
“I have (followerCount) followers”
not
“I have 226 followers”

You'll have to programmatically change an empty element:

<p id=followerCount></p>
<script>
fetch('https://scratchdb.lefty.one/v3/user/info/han614698')
  .then(response => response.json())
  .then(data => followerCount = data["statistics"]["followers"]));
document.getElementById("followerCount").innerHTML = followerCount;
</script>
That works, but I want to put the number in a sentene:

“I have (followers) followers”

<Scratch Wikian | Forum Helper | Almost to 6000 Posts! | Please be aware I may mistype things, my wrist is fractured>

Credit to -gge for the icons in my signature | I condensed all this code into five lines using [p] tags, idk why




han614698
Scratcher
1000+ posts

More HTML Questions

Thanks so much guys, this really helps!
If I need more help, I might come back here.

<Scratch Wikian | Forum Helper | Almost to 6000 Posts! | Please be aware I may mistype things, my wrist is fractured>

Credit to -gge for the icons in my signature | I condensed all this code into five lines using [p] tags, idk why




Powered by DjangoBB