Skip to content Skip to sidebar Skip to footer

Why Am I Getting The Js Error In Line One Of My Script Syntax Error: Invalid Or Unexpected Token?

I'm trying to make the picture on the index.html page change when you push the button. Here's my HTML:

Solution 1:

var lolcatButton = document.getElementById("lolcatButton");

Change the to ". And the other lines.

Solution 2:

You can reorganize your code like this:

<buttonid="lolcatButton"onclick="showMeTheLolcat()">Show me the LOLCat!</button><br><br><imgid="lolcatImage"src=https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat5.jpg><script>functionshowMeTheLolcat() {
var image = "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/cat4.jpg";
lolcatImage.src = image;
}
</script>

Try it on jsfiddle here.

Post a Comment for "Why Am I Getting The Js Error In Line One Of My Script Syntax Error: Invalid Or Unexpected Token?"