what's up y'all this is Hussein Nasser from IGeometry and let us continue with
our beautiful calculator here all right what building today what did we do last
time we did most of these buttons now we can
write in full equation right you can do cool stuff you can clear we can do a
division but we can do it oh we can't even do that small mmm zeros all right
so we can't do all that stuff what we're missing
we're missing the valuation it's really really simple to evaluate that puppy so
let's go ahead and open our calculator that is all co-curator right there guys
all right look at all that good all this kid guys all right what are we going to
do now so we want when we click on that
evaluation or equal the equal button all right we want to evaluate whatever
expression is there on the result is that what it's called
it's called a result okay the good things that we already fetched that we
fetch the result object so we have that object okay so what we're going to do
here is actually it's try to evaluate that let's let's just do that for a
second year we had a lot of code your droid
see that's the last code we introduced another type of function last time
trying to be fancy that's the called the arrow functions
where we actually reset we we click like food someone click clear we reset all
the value Xero's on that so we're gonna do
something similar actually today here
do we have a button in the equal did we give it a name did we give it a name sir
let me hide myself here so so you can actually see the code all right what did
we call that again we called it equal and guess what we actually did not pull
that icon so let's just sew and equal they called document or get element by
ID and it's called equal so let's just call it that very simple very basic all
right so now if someone clicks on equal we want to do something fancy here what
are we gonna do man so let's just use our functions again I'm really really I
like those just one line that does everything and by the way in JavaScript
you can just by the way break things into multiple lines it doesn't have to
be a one single line right okay what do we want to do here it's simpler really
simple so the good thing is I already have that object the result tribe and
what I want to do is actually evaluate that result so literally say result dot
text content is equal to result god alright by dot text content but will
introduce a new function called eval which is literally a built-in function
if either the supplied string as a JavaScript code can you can you imagine
how cool this is right so you give it a string and what it does is actually
evaluate that string as f as was a code basically like one plus
one minus three and then it will actually evaluate that and then compute
the result what are we going to do after the computing the result of that
highlighted portion is put that value in this and you can just ignore the I just
added that so we avoid the proton theses I'm back all right
how about that let's just save and try that I think into that too yeah you can
do anything whatever is more readable for you guys just feel free and do it
just you can write that code like that you can line in one line you can line
break it in multiple line it's all good so let's do 9 plus 9 and they say evil
oh that's a revelation right there guys oh man 6 plus 3 9 is it 9 yes we get 9
times 99 times 9 yeah why not sweet sweet 3 plus 3 7
holy mama look at that plus oh that's wrong Oh so if you did something wrong
and if you equal sexually it will try to evaluate it sometimes it will fail like
in this case it will just do nothing and we will handle that in other cases but
like if you get 6 plus minus 6 what does that mean it's actually 0 6 plus minus 6
I think as if there is there are pearl pieces
on this right so we'll do their parentheses in the next episode I think
and then we're gonna make this much much clearer the ricer list it's just do more
cool stuff 9 over 3 so as you start doing multiple things it will not become
as clear as you know the result there's always like in multiplication and
division and math you know there's always a function that is preferred over
the other right and certain operators are preferred like a multiplication is
preferred over the operands such as the addition and the sub alright so yeah
look at that 9 minus 6 plus I'm having so much fun can we do some more can we
do dis mo three point three plus three points 300 does not like that we'll only
to find out wise did it fail so six plus one point one actually
worked okay so we need to fix that extra zero which is useless
all right so we'll fix that and maybe in the next episode all right so yeah so I
think like eighteen plus three point one it's 21 point one so three point three
plus three point three it did not like that one and I think that's because of
the extra zero there we're gonna fix as well so yeah let's just take it like
today guys and and stick with that as the result so we have I think we have a
functional and functioning calculator obviously there are a lot of things like
divided division by zero you know infinity there's a debate whether it's
infinite or not but yeah alright guys hope you
enjoyed this episode I'm gonna see you in the next one
stay tuned bye bye hey guys so some of you suggested that I end each of these
episodes with a quiz or kind of a question so you guys can take the time
and try exercise it for yourself and OB I think I think it's a great idea so I
started to do that starting this episode so sorry I didn't catch that suggestion
later but yeah so try this guys okay so try solving this problem with with the
tools that we learned so far right you can search the net for other tools but
just in general this is the problem that we have if I click on start over if I
click on any digit I'm starting to add you'll notice that the zero is getting
appended to right so regardless whatever we add we always add the zero so zero
sometimes makes sense to add sometimes it doesn't right so like if if it's an
operator like like plus yeah it's okay right zero plus six but it doesn't make
sense to add zero 9 or 0 8 or right so this is the fix if I clicked on a digit
do not append right if the caret if I click on a digit do
not append that zero try to not happen that 0 if I collect on anything else it
will be ok right so 0 1 2 3 through 9 just to replace the 0 with the number
instead right so so it's just it will be something like that like like that so if
it's 0 like aid but if it's 0 at play Plus this actually takes the plus into
consideration alright dot works too right you can append it so we
or combat guys and I'm gonna see you in the next episode and we're gonna fix
that problem in the next episode stay tuned