So our next step in the project is to solve the mathematical problem where I need to type my age and
add a plus two.
How can I do that?
A simple math equation inside of our code.
So what I'm going to do is let's get the age again, which is the age variable, and do this way I'm
going to get age and add plus two.
So now the age is the age itself plus two.
So when I print the age to the console, it should be whatever I type plus two, Let's save the configuration
and try that out.
Andrea Iacono And the age is 28.
Och did it work?
Sort of.
Kind of.
Yeah.
First name is OC.
Last name is OC.
But the the age is 2228 to.
Actually, it did work in a way.
It's not the result that I'm expecting, but it didn't work because JavaScript took the 28 and add the
number two at the end, and the JavaScript didn't do the actual math calculation because he doesn't
know is a number.
If you point your cursor to the age variable, you should see the age variable is being treated by as
a string.
So JavaScript thinks this is a string is a text and not an integer or a number.
So how can I do that right over here.
Inside of the prompt we have another function called or the reason these function exists is to convert
the strings into a number.
This value in here JavaScript knows is a number, but the variable itself it's a string.
So whenever I type something into the prompt, it's getting to the JavaScript code as a string.
I need to change that.
So how can I change that?
I'm going to call a function named pass int function pass.
INT This function converts as I said, from string to integer.
So parse int open and close parentheses and I'm going to copy and paste or just move these to inside
of the pass int function.
The result should be something like this.
As soon as I type the number two, the number two is a string.
This string is being converted or parse that into a number, an integer and now this should be showing
as a number.
So a number, whatever I type over here, 28, for example, plus two is should equal to 30.
So let's double check before we test that.
As soon as I point to this age.
Age now it's number.
Age is no string anymore.
Over here is a number.
Right over here is a number.
So I should get a result as a number and not string like the other two.
Save the config and let's test.
28.
And my result is 30.
Right now we are getting the right result.
So that's how you can solve this math equation, which wasn't a math problem.
It was just a variable type problem.