I am learning to use javascript, and i am trying to have some text alternate between "bruh" and "moment" after every click. I am trying to store the text's state in attribute "data-state", which (should) alternate between 1 and 2, but i get "Uncaught ReferenceError: Invalid left-hand side in assignment" on line 12.
<html>
<head>
<title>bruh moment</title>
<style type="text/css">
* {text-align: center; color: blue;}
</style>
<script type="text/javascript">
function funcClick(){
var myParagraph = document.getElementById("myp");
if (myParagraph.data-state == 1){
myParagraph.innerHTML = "bruh";
myParagraph.data-state = 2; //ERROR IS HERE
}else{
myParagraph.innerHTML = "click again i dare you";
myParagraph.data-state = 1;
};
};
</script>
</head>
<body>
<p id="myp"; data-state=1;> bruh </p>
<button type="button" onclick="funcClick()">
Click me
</button>
</body>
</html>
expected: click button -> "moment" click button -> "bruh" click button -> "moment" click button -> "bruh"
actual: [Uncaught ReferenceError: Invalid left-hand side in assignment] click button -> "bruh" [Uncaught ReferenceError: funcClick is not defined] click button -> "bruh" [Uncaught ReferenceError: funcClick is not defined]
here is the actual web page in case it helps http://3863.us/