Java script not working on codepen

I am trying to animate images using JS but its not working. The script tag is not coding properly. You can tell bc (everything after the <, is highlighted green). It complains about the var thingy. “Unexpected token var”. I have tried doing something else with JS before and it did not work then either

It would help to link to the pen.

you accidentally copied the html script tags into the JS section?
remove…

<script>
and 
</script>
2 Likes

remove script open and close tag

1 Like

You can think of codepen working like this: The page is being constructed from three files:
index.html
styles.css
scripts.js

As a result, you don’t need to include the <style> or <script> tags in the html files, they are included behind the scenes, similar to the way you don’t need to write an <html> <body> tag to get your html to display in the preview. What you write in the “CSS” or “JS” sections is what you would write in those separate files, and thus, you don’t need to wrap it in an HTML tag. Hope that helps!

i included the body cause i wanted to style the background to be the green color. It was not working when i just did body{} and there was no body tag. when i included the body tag it still did not work. Had to change it to and id and include it in the body tag. Do you have any idea why that happens? Even with the h1 tag. It does not style if you just do h1{}