Java Script Lesson 2: Console log and more possibilities.

This lesson is essentially a continuation of lesson one but it has information that is just as crucial. So we are just going to continue from where we left off.

So as I said before you can only add strings. As these inputs are rightfully not viewed as numbers. Which gives us some pretty interesting options but it also limits us at the same time.

adding strings

For example the code above will give us the same output as the input “Hello World”

different ways to write the code

As you can see both lines of code resulted in the same output but one thing I forgot to mention is that if you are using the addition operator you need to add a space after each word in the sentence otherwise they will end up as one word.

But enough about the addition operator lets use the other operators with numbers.

The first operator that we should use is the subtraction operation which works opposite to the addition obviously and it subtracts one value from the other. The same way it would work in a math problem but it looks a little bit different

Just as expected our result from 10-1 came out to 9. The other 2 main operators work the same way which are division and multiplication. Which means they work the same way they would in a regular math problem. The only difference is what symbols are being used which for multiplication is the star “*” and for division is the backslash “/”.

Division and Multiplication operators

And yes in case you are wondering 9 is my favorite number. But the next thing we can do with these operators is the most useful in my opinion which is combining them to solve math problems very quickly which can get us to our first project which will be making a calculator! But we still have a few lessons before that. Anyway here are some examples of combining operators to solve some equations

Combined operators

As you can see these operators can be used to a near infinite scale and they can calculate all these different equations in an instant which will be the main base for our calculator project that we will be starting soon.

Thank you all for reading and feel free to check out my YouTube channel where I upload video game and cooking things link: