I decided to create a very simple alert with a function. This is how it looks like:
The only problem with this was when I did the callback function. Notice the alert within the function where it says:
alert("There are a total of " + villain + heroes + " villains and heroes that attended this years's villain convention.");
And do you see the callback functions bellow? All it did was add the first number to the second number together. For example like this:
villainConvention(7, 4); (74 is the answer)
villainConvention(8, 3); (83 is the answer)
villainConvention(100, 4); (1004 is the answer)
The same thing happened when instead of the "addition symbol" I used the multiplication symbol. It just multiplied the first number to the second. Like this:
villainConvention(7, 4); (28 is the answer)
villainConvention(8, 3); (24 is the answer)
villainConvention(100, 4); (400 is the answer)
Okay...so for some reason it's not doing what I am asking it to do. Actually, let me rephrase that. It's doing EXACTLY what I asked it to do. But not what I WANTED it to do. I wanted to figure out how many total villains showed up at this famous evil convention and I also wanted to know how many heroes also showed up at this convention to ruin the fun for the villains. I don't want to add both numbers together (either through addition or multiplication). I want to get two separate headcounts! Not a combination of both of them! This is just not going to work.
So I started thinking...what if instead of me putting together both the "villain and heroes" argument by using addition and or multiplication to try to get some kind of response I instead separate the arguments without any math involved? So that way the callback function arguments work the way I want it to? And this is exactly what I did. Just like this:
And guess what? It worked!!! It worked just like I wanted it to! So instead of the callback argument numbers adding and or multiplying each other they are now simply just replacing the name of the argument with the correct values. For example:
villainConvention(7, 4); (7 villains and 4 heroes is the answer)
villainConvention(8, 3); (8 villains and 3 heroes is the answer)
villainConvention(100, 4); (100 villains and 4 heroes is the answer)
Yes! This is exactly what I originally wanted it to do. And I figured it out all on my own just by playing around with the code and testing it out on my browser until I got it to do what I wanted it to do. It felt awesome when I figured it out all on my own!
I also decided to take it a bit further and see if I could make my small little coding project a little bit more complicated using everything that I had just learned. I love video games and one of my favorite games on my Xbox is "Tomb Raider A Survivor is Born" and the sequel "Rise of the Tomb Raider."
Now if these arguments were numbers that I wanted to add and or multiply instead of having just phrases I then wouldn't have needed to declare all these variables like I did to all these phrases. All I would do is simply put the numbers I wanted to add or multiply in the callback function and call it a day like I did with my villain convention code. I didn't have to declare any variables in that villain convention code at all. But it seems that things get a lot more complicated when you want to callback phrases instead of numbers.
I know there are probably other ways of coding this example that I have not discovered yet. But...at least I can say that what I did worked for me! And I'm looking very much forward to learning other methods that would come to the same conclusion or an even faster conclusion.