So in the above example I entered five plus five which of course returns ten as expected, however the same does not happen when one of the operands is a string of the number five. It does not result in an error, but returns the string “55”. This is because in javaScrit the addition operator is used for both addition and string concatenation.
There are many ways to go about getting references to one or more html elements in the page. In this example I am using the query selector all method to get all paragraph elements in the page by passing a string of the tag name for a paragraph element. So then then this method allows for getting one or more elements by way of a tag name, however it can also be used to select tags by way of class names, and id tags also.
The array map method is a way to create a new array with elements that are based off of the content of a source array to which it is called off of. The source array in this case though is an html collection so I call the array map method with the function call method and pass the reference to the html collection that I get with the query all method as the first argument to the call method, then I pass a function that I want t be called to create the new value for the resulting new array that will be returned made with map. Inside the body of this function I am returning the inner text of each paragraph element. I am then using the array join method to join each paragraph text together into a single string, and I am placing a header element between each text. The final string value is then set to the inner html of the body element by way of the reference to the body element in the document object.
What this does is it creates a singe global variable called sm for swarm sim by returning a pubic api within the body of an IIFE. This global variable is an object with a few public methods attached to it. Once of which can be used to get a reference to a given tab in the navigation bar of the game, another can be used to get the link to a given upgrade, and another will get the max button when it comes to buying upgrades for an upgrade. These methods can be used manually to get a reference to an item that is to be clicked, and then I can call the click method off of one of these element references to simulate a click. However there is also a method that can be called to start or stop and internal loop powered by the set interval method that will do so automatically.
After that there is calling the sm.toggleAutoClick to start auto clicking upgrades for the game with default settings. The method can then be called again to stop the process of auto clicking. There are a whole lot of auto clicker programs that can also be used to do something like this, however with this kind of code there is the potential to make the code something morn than just a simple auto clicker. I did not take the time to do so, but there is the idea of working on this a little longer to make something that will fully automate the process of playing the game.