Check out a free preview of the full Calculator Project: JavaScript course:
The "Inserting Symbols" Lesson is part of the full, Calculator Project: JavaScript course featured in this preview video. Here's what you'd learn in this lesson's course:

Brian begins coding the section of the program that handles mathematical and other symbols.

Get Unlimited Access Now

Transcript from the "Inserting Symbols" Lesson

>> Brian Holt: Welcome back. Hopefully you had a good shot at this. And right now we're gonna take a look at it. The one thing I was doing here as I was converting all of these to HTML entities, you could totally just put like an asterisks here and then, like that's what that would look like right there.

I like having like a little X symbol there. So notice that this looks like an X, rep but this is actually like a multiplication sign, right? It's not just like a normal X. So let's just put them next to each other and you can see what they look like.

You can see here they are a little bit different.
>> Speaker 2: If I do it the same as the stand, times, cuz that's what I have on mine.
>> Brian Holt: Is it like?
>> Speaker 2: Yeah, that's [INAUDIBLE].
>> Brian Holt: Yeah. Okay, same thing, same idea cool. I can just never remember this, so times like the, there's some fancy name for but it's the formal name for it and then what I showed you is just the code for it.

>> Brian Holt: So is this one like and division or something like that?
>> Brian Holt: I didn't know that. VS code will do that for me, that's cool. And this is back arrow.
>> Brian Holt: Uh-huh?
>> Brian Holt: All right, neat. Cool, so now mine looks like it should.

Did we mostly all get to this point at least?
>> Brian Holt: If not, there is a CodePen where you can check out basically up to this point. Okay, getting here so we just did handle numbers, so now we can actually click this. We're not doing anything with those numbers and if we click any of these other things it's just ignoring it, right that's where you should be to this point.

>> Brian Holt: Let's see, if we refresh here also notice that something that's kind of fun that we kind of accomplished, I would say sort of by accident. If I press the zero a bunch of times you wouldn't expect it to be zero, zero, zero, zero, right? You would expect it to just stay zero until they actually click a real number.

And we did that just because if buffers triple equal to zero, then it just says numbers assigned or buffers assign numbers string, so then it's gonna be reassigned to zero, right? And then, this is always going to be true as long as that first thing is 0, right?

So that's kind of a neat thing that I wasn't necessarily planning to happen, but it kind of happened just by writing code this way, does it make sense?. Cool.
>> Brian Holt: But it does work once you do at a number. Okay, so now we have numbers, the numbers are handled.

Now we want to handle symbols.
>> Brian Holt: So going to handleSymbol. And we're gonna do different things, depending on whether or not it's some sort of math operation, depending if they hit equals, depending if they hit clear or something like that. So let's handle clear, I think that's a pretty easy one to deal with.

So if.
>> Brian Holt: That our symbol triple equals C, right? So they clicked the C button over here. Then, so what happened? I want you to think about this for a second before I tell you, what do you think's gonna happen if they hit C, what are the steps that I need to take to clear out everything.

So if we go over to the one that's finished, it's just minus there we go. If I hit 25 and then I hit C, what happens?
>> Brian Holt: Okay. I expect the buffer to clear out, I expect the buffer to go back to zero. So, let's do that. Buffer is assigned zero.

>> Brian Holt: What happens if I have some sort of running total going here, all right? Like I've added 15, and then 30, and then 35? Probably expect that all to clear out as well, right? So we're gonna say runningTotal = 0.
>> Brian Holt: And that should probably be enough at least for now.