-1

so I'm using this Javascript (API) that has a bunch of function. How do I go about writing it to an HTML file?

so one of the function is "api.ping()" which works fine on powershell, but I cant get it to print that in an HTML file.

So in the script I wrote document.getElementById("demo").innerHTML = api.ping();

and the HTML is

<!DOCTYPE html>
<html>
<body>
<script type="index.js"></script>
<p id="demo"></p>
</body>
</html> 

I'm trying to put the value returned from the call onto the HTML file.

1 Answers1

5

I think your index.js file is probably not being included. You'll want to change the tag line to read:

<script type="text/javascript" src="index.js"></script>

Assuming that index.js is in the same directory as this HTML file.

freefall
  • 253
  • 1
  • 8
  • 1
    This ^^^ -- you have mixed up the src and type properties - index.js needs to be in the src property. If this fixes your problem, show Zach some love by accepting his answer. – Jim Speaker Dec 14 '19 at 22:02
  • Hey, yea they are in the same directory. And I tried that but didnt work. I'm not too familiar with javascript, is there something else I should be doing? – Jithin Sunny Dec 14 '19 at 22:39
  • @JithinSunny if adding the 'src' attribute didn't fix the problem, I'd then try moving the entire '' line below your '

    ...

    ' (putting it right before the closing

    tag)

    – freefall Dec 14 '19 at 23:03