# Built my Calculator

**URL:** <https://forum.freecodecamp.org/t/built-my-calculator/460629>\
**Category:** I Built This\
**Created:** [May 17, 2021, 8:07am UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629 "2021-05-17T08:07:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![iicestudio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iicestudio/32/216910_2.png) [@iicestudio](https://forum.freecodecamp.org/u/iicestudio)\
**Post date:** [May 17, 2021, 8:07am UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/1 "2021-05-17T08:07:50Z")

</div>

I am still on JavaScript basics. I decided to do one of the projects and built myself a calculator. It wasn’t difficult since JavaScript had a built-in function eval(). I wanted to share and tell me what you guys think

[https://codepen.io/iicestudio/full/JjWKQYj](https://codepen.io/iicestudio/full/JjWKQYj)

Version II  
[https://codepen.io/iicestudio/full/MWppjWq](https://codepen.io/iicestudio/full/MWppjWq)

Version III  
[https://codepen.io/iicestudio/full/jOBBerj](https://codepen.io/iicestudio/full/jOBBerj)

---

<div class="post-metadata">

**Author:** ![Roma](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/roma/32/112899_2.png) [@Roma](https://forum.freecodecamp.org/u/Roma)\
**Post date:** [May 17, 2021, 6:55pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/2 "2021-05-17T18:55:35Z")

</div>

It looks okay @iicestudio. Some things,

- there’s no keyboard accessibility
- you should not allow a number like _5_ to be preceded by one or more zero’s
- this, _5.5.5_ should not be allowed

On a side note, I don’t believe the JS section has you build a JS calculator. That’s in the front-end section and you’ll want to use React to build the calculator.

---

<div class="post-metadata">

**Author:** ![iicestudio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iicestudio/32/216910_2.png) [@iicestudio](https://forum.freecodecamp.org/u/iicestudio)\
**Post date:** [May 17, 2021, 7:13pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/3 "2021-05-17T19:13:28Z")

</div>

> [@Roma](#):
>
> there’s no keyboard accessibility

Completed

> [@Roma](#):
>
> this, _5.5.5_ should not be allowed

I got this fixed

> [@Roma](#):
>
> On a side note, I don’t believe the JS section has you build a JS calculator. That’s in the front-end section and you’ll want to use React to build the calculator.

Yeah I cannot go on React yet. I don’t even have a solid grasp of JavaScript. And thank you for your feedbacks as always

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [May 17, 2021, 7:39pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/4 "2021-05-17T19:39:36Z")

</div>

> [@iicestudio](#):
>
> > [@Roma](#):
> >
> > there’s no keyboard accessibility
> 
> Completed

Do you have an updated codepen link that includes this accessibility enhancement?

---

<div class="post-metadata">

**Author:** ![iicestudio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iicestudio/32/216910_2.png) [@iicestudio](https://forum.freecodecamp.org/u/iicestudio)\
**Post date:** [May 17, 2021, 7:43pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/5 "2021-05-17T19:43:43Z")

</div>

It should be the same link

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [May 17, 2021, 7:55pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/6 "2021-05-17T19:55:14Z")

</div>

OK, the calculator at that link still isn’t quite keyboard accessible. One of the basic rules of accessibility is to use the semantically correct HTML element when available. I would say that all of the buttons on your calculator are in fact “buttons” and thus should be using the `<button>` element instead of `<div>`. Change them all to `<button>` and you will automatically gain all the keyboard accessibility you need.

FYI, these buttons are not accessible right now because I cannot Tab to them with my keyboard and thus I can’t “click” on them with my keyboard.

---

<div class="post-metadata">

**Author:** ![iicestudio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iicestudio/32/216910_2.png) [@iicestudio](https://forum.freecodecamp.org/u/iicestudio)\
**Post date:** [May 17, 2021, 7:57pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/7 "2021-05-17T19:57:54Z")

</div>

I can change them into buttons but why use Tab when you can just press the numbers

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [May 17, 2021, 8:12pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/8 "2021-05-17T20:12:54Z")

</div>

> [@iicestudio](#):
>
> why use Tab when you can just press the numbers

Good question. Some screen readers may hijack certain keys and thus the user won’t be able to just press on a key and have it work the way you want it to, especially since this isn’t a form so the screen reader won’t go into form mode but rather stay in document mode. Some browsers may also hijack certain keys. For example, when I press “/” using Firefox my browser opens up a search bar and the focus goes directly into that bar, so I can’t just press the “/” key and use it in your calculator. The Tab key is special and will never do anything other than move you to the next focusable element (or backwards to the previous focusable element if you hold down Shift), so Tab is guaranteed to work no matter what screen reader/browser someone is using. Tab is basically the foundation of keyboard accessibility and you should always be able to Tab to all focusable/interactive elements on the page.

But really, as I mentioned earlier, one of the basic rules of accessibility is that you should use the semantically appropriate element when possible and clearly these are buttons and thus you should use a `<button>`. Technically, there is a way you could continue to use `<div>` but it requires extra work, both in the HTML and with JS, and I’m not going to elaborate further on that because I don’t see any reason why you shouldn’t just use `<button>`s. I can tell you from personal experience that my projects would never pass accessibility audits where I work if I used a `<div>` for an obvious `<button>`.

---

<div class="post-metadata">

**Author:** ![iicestudio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iicestudio/32/216910_2.png) [@iicestudio](https://forum.freecodecamp.org/u/iicestudio)\
**Post date:** [May 23, 2021, 6:02am UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/9 "2021-05-23T06:02:05Z")

</div>

My JavaScript skills were lacking so I kept redoing my calculator. And I wanted to share the result

[https://codepen.io/iicestudio/full/jOBBerj](https://codepen.io/iicestudio/full/jOBBerj)

---

<div class="post-metadata">

**Author:** ![Roma](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/roma/32/112899_2.png) [@Roma](https://forum.freecodecamp.org/u/Roma)\
**Post date:** [May 23, 2021, 6:08am UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/10 "2021-05-23T06:08:30Z")

</div>

> [@iicestudio](#):
>
> My JavaScript skills were lacking so I kept redoing my calculator. And I wanted to share the result

It’s good to play. That’s how we learn. Some takeaways,

- divide 7 by 3 and see what happens on the screen
- narrow your browser window and do that same calculation (not a good UX)
- my eyesight is somewhat good so I notice the slight improvement to keyboard accessibility but to anyone with sight issues it still needs to be improved.

---

<div class="post-metadata">

**Author:** ![iicestudio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iicestudio/32/216910_2.png) [@iicestudio](https://forum.freecodecamp.org/u/iicestudio)\
**Post date:** [May 23, 2021, 6:12am UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/11 "2021-05-23T06:12:56Z")

</div>

Yeah I noticed that but my primary focus was to expand my JavaScript skills. I will focus more on the UX once I get to the calculator project using React

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [November 21, 2021, 6:13pm UTC](https://forum.freecodecamp.org/t/built-my-calculator/460629/12 "2021-11-21T18:13:04Z")

</div>

Closed on November 21, 2021, 6:13pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
