what's up y'all this is Hussein Nasser from IGeometry bringing you software
engineering by example and today's examples actually building a calculator
today's topic is JavaScript so javascript by example alright guys so
yeah actually I had to record this episode again my mic was off and I went
like truthful through a 12 minute and then I discovered oh there's no audio
hmm so wasn't really useful you will see just someone just took yeah yeah all
right so in this video we're gonna solve one of the problems that we have one of
the bugs that we have in this software in order to solve this we're gonna
introduce a new tool alright okay so to fix this problem as look at that first
the problem is when I click a digit and the current value is zero
we're actually appending that and we don't want it we don't want to do that
we only want if if we only want if it's a digit then I'm pressing and the value
is zero I want to override that but if it's an operation it's cool to do that
like keep the zero and then plus 6 and then minus 3 and then plus zero right
you can do that that's cool but if the current value is zero and you're
pressing a digit one of these puppies we always want to override that okay
otherwise we want a pen so how can we fix this problem right how can we fix
this let's go to our function here called print symbol if you have the code
guys by the way it's called is always in the description below I always point the
latest code so he can access that you can follow the github repo to actually
see all the episodes and source code for every episode there is alright so what
we wanted here's ask ourselves a question if the
current value that we are pressing is a digit right and the value is zero that
current value is zero overwrite otherwise append alright
again let's repeat that to see we just we just introduced a new concept here we
teaching our code something it doesn't know how to do before we TGA conditions
if I'm clicking on a digit which is nine or a six hour three or two or one right
then overwrite don't append don't happen the current zero to that just override
it so how can I do that so we ask ourself a question here so how do I
check if it's a zero what is the zero here that's the value right the action
result if this is equal is zero so what did we write here so this is the
conditional statement so if this is a keyword you had parentheses that's the
condition right and the result the text content is this if that value it happens
to be zero so now you notice that there is a double equal here instead of the
regular equal the regular equal means an action hey go and assign the right-hand
side to the left-hand side this is actually a question as this equal to
this it's an actual binary result does this equal to this so it either returns
one or zero otherwise this is actually overriding the value whatever on the
right-hand side put in the left-hand side so if it is zero what do we want to
do if it's a digit we'll worry about that if whether it's a digit or not
later but I want if this is true if this is a result
zero then go ahead and just override the object the text content which is what
object I clicked on here override it regardless else do this so this means
either these one of these will get executed not both right and this is very
critical programming you have to I want to execute one path but not the other
can we save and test our stuff if it's zero override if it's not zero then
append hmm we'll check out nine that's cool
it actually wrote the nine overriding the zero six it actually appended now
that is kulish kulish nine how about zero plus we don't want that we won't
actually if it's as plus and minus and multiplication division we won't append
so how can we fix this there are like literally tens of ways to fix this
problem you can add more if statements now that you know how to do if statement
you can actually what do you know what do you want what you can do is write
another function called print this is print symbol right and this works only I
want this logic to be executed only when I click digits so one two three four to
nine and a zero obviously alright but I do not want this logic to execute on the
rest of the stuff so how about we call this function we copy this function and
we call this print digit and this is pretty simple so we have two functions
brandish it if some comments if the clicked of
is a digit like one two three four zero we have this special logic where if it's
zero then override otherwise yeah but print symbol guess what I always want to
override a simple if it's anything else hmm interesting
okay that sounds good if it's a symbol like these append regardless so that's
our original code if you remember otherwise do this
well trick so let's go to our events here remember these guys remember go
back to the third episode you're gonna watch these so number zero that's a
digit so I don't want to call print symbol for it I want to call Brandon
eight and number one - right - right - right - right - right - right
yup so these now go through a different path my friend right that's fine try
that three Oh mamacita look at that oh nice look this is what do I want
we want our pad nice this is cool guys this is kulish so 9 x 9 flash fray - 2.1
this is amazing this is amazing amazing stuff all right guys we gotta stop here
so we did we introduced the calculator conditional statements right I'm gonna
push this code - to get help right right in a second now here but but yeah so
what do we want for the quiz for the next episode
yeah all right okay all right so this is something that you
guys you can do it yourself but I'm not I think I think I'm not gonna do it now
that you know conditional statements how about you do this fix this bug see this
is not this this is not a mathematical equation that doesn't make any sense
right so try if this is I think this is a bit difficult but try give it a shot
so if you just clicked on a multiplication or or or division or an
operator you can only click on one operator at a time
this is kind of validation that we can introduce but try to fix that it's a bit
little bit challenging but give it a shot
right so we what we don't want is if someone attempt to like click plus and
then he tried to add another operator so another symbol so he tried to add two
symbols consecutively we want to block that right
that's your quest for the next episode and the next episode we're gonna do
something different right if you ask me to do that we're gonna do it obviously
but well let's see right Oh take yourself into this challenge you know
variables I think we introduced variables so we're gonna use variables
to do that if I click on the plus users can't click on two operators
consecutively right we need to break that so that's one way to fix it you try
to fix it try to fix this but we will introduce effects for this instead
tomorrow not tomorrow whatever we can we can fix this fat calculator full body to
calculator look at that look at that we're gonna fix that all right guys all
right have a great evening morning afternoon guys subscribe like
this video all right and keep watching keep subbing keep liking see you in the
next one goodbye