I am making my own programming language using JS but when I attempt to put multiple words where it is expected to be an error, it has no errors, I don't know why .includes only gets one string and skips the others, could I get any help on the subject??
HTML:
<!DOCTYPE html>
<html>
<head>
<title>HyperAnimator</title>
</head>
<body>
<h1>HyperAnimator:</h1>
<br>
<b>Dark mode: <button onclick="DarkMode()">Toggle dark mode</button>
<br>
<br>
<b>Input code:</b>
<br>
<!--<input type="text" id="Code">-->
<textarea id="Code">
Main Anim[] class=>
<=ClassEnd</textarea>
<br>
<button onclick="Compile()">Compile</button>
<br>
<br>
<div id="Compiled">
</div>
</body>
</html>
CSS:
h1 {
font-size: 25px
}
#Code {
border: 5px solid black;
font-family: Arial, Helvetica, sans-serif;
font-weight: bolder;
height: 200px;
width: 400px;
overflow: hidden;
text-align: left;
color: black;
}
body {
background-color: white;
color: black;
font-size: 25px;
}
.dark-mode {
background-color: black;
color: white;
}
button {
background-color: white;
border: 5px solid black;
font-weight: bolder;
}
button:hover {
background-color: lightgrey;
}
b {
font-size: 20px;
}
#Compiled {
border: 5px solid black;
height: 200px;
width: 400px;
background-color: white;
color: black;
}
textarea {
max-width: 400px;
max-height: 200px;
}
JS:
let ClassTagAmount = 0;
let CurrentClassSelected = "none";
let Code = document.getElementById("Code").value;
function Show(code){
document.getElementById("Compiled").innerHTML = code;
}
function DarkMode() {
var element = document.body;
element.classList.toggle("dark-mode");
}
function Compile() {
ClassTagAmount = 0;
let Code = document.getElementById("Code").value;
if (Code.includes("Main Anim[] class=>") == true){
ClassTagAmount += 1;
}
if (Code.includes("<=ClassEnd") == true){
ClassTagAmount -= 1;
}
if (ClassTagAmount == 0){
console.log(Code)
console.log(ClassTagAmount)
}else{
Show("Syntax Error: Unexpected missing starting or ending class token")
console.log(ClassTagAmount)
}
}
Whenever I put multiple of the same string, it should count both of the same strings and make the ClassTagAmount variable become -1 or 1 but instead it is 0, when it is only one string it works but with multiple strings it just becomes 0.
EG: Test A(
Input:
Main Anim[] class=>
<=ClassEnd
Output:
Main Anim[] class=>
<=ClassEnd
0
)
Test B(
Input:
Main Anim[] class=>
Output:
Syntax Error: Unexpected missing starting or ending class token
1
)
but...
Test C(
Input:
Main Anim[] class=>
Main Anim[] class=>
<=ClassEnd
Error Output:
Main Anim[] class=>
Main Anim[] class=> //this line is being forgotten.
<=ClassEnd
0
Expected Output:
Syntax Error: Unexpected missing starting or ending class token
1
)
I was expecting so there is an equal amount of the two tags, Main Anim[] class=> and <=ClassEnd but when I put these two not equally then the program thinks it is an equal amount, I expected an error as it is not equal to eachother as either there is two start tags and one end tag or one start tag and two end tags, thus is should output 1 and the error but instead it shows 0 as it seemed to skip all other text except of the closest one.