#Visitor Count showing 'undefined'

6 messages · Page 1 of 1 (latest)

eternal perch
#

Hi team! Super excited to be part of this challenge. Could someone englighten me? My visitor count should work (also fixed the CORS issue) and there is no error message. The only issue is that it keeps showing the following when I go on my url: "Visitor count: undefined"

My code is the following:
'''
<body>
<h1>This is my test page</h1>
<p>Visitor count: <span id="visitor_counter"></span></p>

<script>
  fetch('API_GATEWAY_URL')
    .then(response => response.json())
    .then((data) => {
      document.getElementById('visitor_counter').innerText = data.Count
    })
</script>

</body>
'''

Has anyone experienced the same? I have been stuck for a long time on this bug now. Thanks a lot for your help!

amber portal
#

there in fact is someone who had a very similar issue in #code-review a few hours ago. could you show me what "data" looks like? if you are unfamiliar with how to show that, put a console.log(data) above that document.getElement... line, and that should show the object in the browser console once you refresh

nova comet
#

I had this issue for a long time, my code was referencing the wrong value from the response; double check what your response looks like (use Postman for this) and adjust accordingly

eternal perch
#

Thanks a lot for your answer ! So happy to get some inputs on this.