Need help with putting javascript in html

how do I insert js into HTML it isn’t showing up on the web browser thing

Repl link:

my code is supposed to make a bus that can be controlled by the arrow keys

bus_game

You can put JS inside by using the script tag.

This JS code will run and won’t be visible to the user.

1 Like

Put this inside the body

<script>
// js code
</script>

or if the JS file is external

<script src="file.js"></script>

@HexHands @OmegaOrbitals did you guys even… look at the Repl?..

1 Like

You guys didn’t even bother to look at the code xD.

1 Like

May I ask where these magic functions like “background” are coming from? Did you mean to use a lib? You should probably follow the cdn installation instructions for that lib.

1 Like

No, why would we need to? He’s asking how to insert JS into HTML, and I pretty much told him how.

Because in his Repl the first thing in his HTML is a script tag. That’s why you would need to.

4 Likes

ok, so what is a lib and how do I install one?

Well, first, tell use where you got these functions like “background” from.

1 Like

I got it from Khan academy because that was where I was learning js.

my code was working here:

That will only work in Kahn academy. It uses a Kahn academy lib that only works in there afaik. So, if you want to use it on replit, I recommend using something like kaboom.

2 Likes

So if I use kaboom in theory my code should work, right?

No, you would have to re-write it for kaboom. As I said, it should only work in Kahn,

oh ok, so if I didn’t want to use a lib then I would have to replace the function background with a big rect(); that covers the whole canvas on that line instead. or would that not work?

That would probably work. I am not an expert XD

ok thank you for the help.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.