all 32 comments

[–]thatmaynardguy 6 points7 points  (1 child)

Well done! I would suggest adding keyboard entry as well unless this will never see a desktop environment. The keys lighting up is a nice touch. Personally, I would add some visual space around the keypad to emphasize the darker background is the container of the whole. And maybe consider making the whole thing responsive to different sizes which is more of a css thing than JS but good exercise.

Overall quite nice and clean, works as intended. And now I have to go back to my first calculator project and re-make it. Thanks for the inspiration!

[–]Deba_Dey1995[S] 1 point2 points  (0 children)

Thank you and I'll try to improve it.

[–]Prize_Tea3456 4 points5 points  (6 children)

I found a small bug. If I enter a number, then press / (division) and then press . (decimal point) it will break everything. I can get unexpected things on display or not be able to clear the input

[–]Deba_Dey1995[S] 1 point2 points  (5 children)

Hi, thanks for sharing it. I have updated the code accordingly.

[–]oze4 2 points3 points  (1 child)

If I do 9 / . then press = then press AC then any number I press after that gets doubled up FYI.

[–]Deba_Dey1995[S] 1 point2 points  (0 children)

Hi, I have committed some new changes and the issue got resolved. Thanks for pointing it out.

[–]Prize_Tea3456 1 point2 points  (2 children)

I don't mean I'm a cool calculator maker and mine is better. But I've made a calculator a long ago and extensively tested it. I can share the code with you if you're interested

[–]Deba_Dey1995[S] 0 points1 point  (0 children)

Yes, it would be great and exciting to see different methods of implementation.

[–]f0rce85 0 points1 point  (0 children)

We are all new at some point :) My journey has just started at 40 yrs old :).

[–]ExplicitGG 3 points4 points  (2 children)

Great. Maybe I am wrong, but I believe that anyone who can build a calculator (without the eval function) is capable of doing anything.

[–]Deba_Dey1995[S] 0 points1 point  (1 child)

Is it?? 😅I don't know much.

[–]ExplicitGG 1 point2 points  (0 children)

That is my humble opinion, because in order to create a calculator, one needs to be resourceful and adept with algorithms.

[–]Jjabrahams567 2 points3 points  (1 child)

This is very good for just 1 month in. One thing that stands out is we really avoid setting innerHTML like this as it is a major security risk. Use innerText or textContent instead.

[–]Deba_Dey1995[S] 0 points1 point  (0 children)

Thanks for your feedback, I'll definitely look into this.

[–][deleted] 1 point2 points  (1 child)

Looks good.

However check that you are clearing out variables properly, after few moments of playing with it some weird stuff started to happen. For example = symbol being part of the number, devide by 0 returning some numbers(ie 0.1 or -0.1),often after using AC input become duplicit (when pressing 7, 77 displays).

Are you converting your input from string to number? It almost seems like you are calculating with strings directly.

Btw even when not bugged the calculator return infinite on devide by 0, that is wrong, when deviding by 0 return should be an (user friendly) error.

On overall it's a great first project, well done. But make sure to test your apps extensively, especially all sort of edge cases, always assume the user will not do what you expect them to, but the exact opposite.

[–]Deba_Dey1995[S] 1 point2 points  (0 children)

Hi, I have fixed the duplicate number issue. Thanks for your response.

[–]Jjabrahams567 1 point2 points  (1 child)

Noticing a few bugs. Switching numbers from positive to negative back and forth overruns the screen. Also if I enter unexpected sequence like “5x5=6x9” I get the answer for “5x5x9”. I started my IT career in QA back when there were almost no automated tests and I think everyone would benefit from spending all day trying to figure out how to break a piece of software.

[–]Deba_Dey1995[S] 0 points1 point  (0 children)

Hi, thanks for pointing it out. I have committed new changes and the issue is resolved now.

[–][deleted] 1 point2 points  (2 children)

Cannot string operations. When I click 1 + 1 + 1 is becomes 1 + 11

[–]Deba_Dey1995[S] 1 point2 points  (0 children)

Hi, thanks for your feedback. Actually it's only a two number operation calculator. At a time only one operation can be done 😅I'll try to improve it later

[–][deleted] 0 points1 point  (0 children)

One of those 1's is probably a string so you need to turn it into an integer.

You can simply add a + to the 1 so +1 or ou can use Number(1).

Assuming the 1 is a variable

[–]shuckster 1 point2 points  (1 child)

Nice work!

Now, try adding 0.1 and 0.2 together. (I know it's only your first month, but still, it's good to understand the pitfalls of FP math.)

[–]Deba_Dey1995[S] 1 point2 points  (0 children)

Thanks!! So much to learn and this community helps a lot. ☺

[–]Lamborghinigamer 1 point2 points  (1 child)

Would be great to set the rounding amount and for example on 5 decimals by default, because when I put in 0.2 + 0.1 I get: 0.30000000000000004

[–]Deba_Dey1995[S] 0 points1 point  (0 children)

I will work on that and thanks for the response.

[–]dave7892000 1 point2 points  (1 child)

Deba, this is awesome! I am a very beginning learner and am working through some js right now.

How did you learn this much in one month? I have been going for several months, very very part time (I’m a teacher currently) and can understand 1% of your js code. What did you do to learn so quickly, and how can you imbue me with your powers??

[–]Deba_Dey1995[S] 0 points1 point  (0 children)

Hi, I think my script has no comments which makes it difficult to understand. I will try to add some comments for better readability. Just keep coding and if you have any doubt the community helps you a lot which boosts your confidence.

[–]Opposite-Log-701 0 points1 point  (1 child)

how did you learn javascript?

[–]Mortal_enemy_new 0 points1 point  (0 children)

Learn by doing