Javascript By Example L1E06 - Fix Leading Zero Bug with Conditions
Skills:
JavaScript Fundamentals80%
Key Takeaways
Fixes a leading zero bug in a calculator using JavaScript and conditions
Full Transcript
what's up y'all this is Hussein muscle from IGM tree 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
Original Description
Full Javascript By Example Series Playlist https://goo.gl/7ZF5TR
In this episode we fix one of the annoying bugs, we had to introduce if statements and conditions. Stay tuned until the end for today’s quiz ..
Source Code: https://github.com/hnasr/javascript-by-example/tree/L1-Episode06
Stay awesome
Hussein
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Hussein Nasser · Hussein Nasser · 30 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
▶
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Extending ArcObjects (IGeometry) - 01 - Getting Started
Hussein Nasser
Extending ArcObjects (IGeometry) - 02 - The Document, The Map and The Layers
Hussein Nasser
Channel Update - New Book, New Job, New Videos
Hussein Nasser
Learn Programming with VB.NET - 01 - Getting Started
Hussein Nasser
Learn Programming with VB.NET - 02 - Classes and Objects (Part 1)
Hussein Nasser
Learn Programming with VB.NET - 03 - Classes and Objects (Part 2)
Hussein Nasser
Learn Programming with VB.NET - 04 - User Interface
Hussein Nasser
Learn Programming with VB.NET - 05 - By Value v. By Reference
Hussein Nasser
Learn Programming with VB.NET - 06 - Variable size, 32 bit vs 64 bit
Hussein Nasser
Learn Programming with VB.NET - 07 - Conditional Statements
Hussein Nasser
Learn Programming with VB.NET - 08 - Inheritance
Hussein Nasser
Learn Programming with VB.NET - 09 - Strategy Design Pattern
Hussein Nasser
Learn Programming with VB.NET - 10 - How did I learn programming
Hussein Nasser
IGeometry 2016 Retrospective - Channel Update
Hussein Nasser
Javascript by Example - The Vook
Hussein Nasser
Vlog - Keep your servers close and your database closer
Hussein Nasser
Vlog - Client/Server Programming Languages
Hussein Nasser
Javascript By Example L1E01 - Getting Started
Hussein Nasser
Persistent Connections (Pros and Cons)
Hussein Nasser
Javascript By Example L1E02 - Building the Calculator Interface
Hussein Nasser
Happy new Year from IGeometry!
Hussein Nasser
Synchronous v. Asynchronous
Hussein Nasser
Javascript By Example L1E03 - Displaying the Digits on Calculator Screen
Hussein Nasser
Show Your Work. Blog, Vlog, Write, Create and Develop!
Hussein Nasser
Relational Database Atomicity Explained By Example
Hussein Nasser
Javascript By Example L1E04 - Operators, All Clear with Arrow Functions
Hussein Nasser
What Comes First, User Experience or Software Architecture?
Hussein Nasser
Javascript By Example L1E05 - Evaluate the Calculator Expressions with eval
Hussein Nasser
Fastest Way to Learn Programming Language or Technology
Hussein Nasser
Javascript By Example L1E06 - Fix Leading Zero Bug with Conditions
Hussein Nasser
Stateful vs Stateless Applications (Explained by Example)
Hussein Nasser
Javascript By Example L1E07 - Running our Calculator on the Mobile Phone
Hussein Nasser
Advice for New Software Engineers and Developers
Hussein Nasser
Why JSON is so Popular?
Hussein Nasser
Building Scalable Software - SLA, HS, VS
Hussein Nasser
Vlog (Istanbul) - Datacenter Proximity
Hussein Nasser
Should Software Engineers Learn Bleeding-Edge Technologies?
Hussein Nasser
Do Developers Build Bad User Interfaces/Experience?
Hussein Nasser
Learn By Doing.
Hussein Nasser
I Wrote Bad Front-End Code That Broke Chrome
Hussein Nasser
My Story
Hussein Nasser
Vlog - Horizontal vs Vertical Scaling
Hussein Nasser
Can User Experience Help Build Better Rest API?
Hussein Nasser
Reverse engineering Instagram in flight mode
Hussein Nasser
The Benefits of the 3-Tier Architecture (e.g. REST API)
Hussein Nasser
Stateless v. Stateful Architecture (Podcast)
Hussein Nasser
The evolution from virtual machines to containers
Hussein Nasser
Proxy vs. Reverse Proxy (Explained by Example)
Hussein Nasser
Canary Deployment (Explained by Example)
Hussein Nasser
No Excuses
Hussein Nasser
Synchronous vs Asynchronous Applications (Explained by Example)
Hussein Nasser
What is an Asynchronous service?
Hussein Nasser
Difference between Client Polling vs Server Push in Notifications
Hussein Nasser
Software vs. Hardware AdBlockers (Explained by Example)
Hussein Nasser
HTTP Caching with E-Tags - (Explained by Example)
Hussein Nasser
Simple Object Access Protocol Pros and Cons (Explained by Example)
Hussein Nasser
Nodejs Express "Hello, World"
Hussein Nasser
Reverse Engineering Instagram feed
Hussein Nasser
Popup Modal Dialog with Javascript and HTML
Hussein Nasser
MIME and Media Type sniffing explained and the type of attacks it leads to
Hussein Nasser
More on: JavaScript Fundamentals
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Your event store is already your audit log
Dev.to · Marc
Distributed Transactions in System Design: Why Data Consistency Becomes Hard Once Your Application…
Medium · Programming
Monolith vs Microservices: A Real-World Architectural Autopsy
Dev.to · Erwin Wilson Ceniza2
FOV in FPS Games: The Math Behind Field of View Settings
Dev.to · Alex Carter
🎓
Tutor Explanation
DeepCamp AI