React Calculator : feedback

Hi everyone !
Finally I have completed my calculator project, and I m excited to hear your notes.
Thank you in advance!
React_Calculator

Hi @houc.bh90,

  • General comments:

    • Why did you use classes and not functions? I’m not saying that is wrong. There is a reason to not use functions?

    • Your project has no comments, and because of that is really difficult to grasp the “shape” of your solution.


  • Inputs

  • Your project at the moment can’t parse (handle) this input:

0.000


I tried determine why, but I had some limitations:

  • I don’t know how to debug code in codepen
  • I couldn’t determine the state of the program (because I didn’t executed the code)
  • Because of the lack of comments I had to assume some elements of the program ("." is a number, a string or a special type()?)

So, this is more or less a guess:

input: 0.00

line 47 zero, 0, typeof number? (There is no comment about this)

state input next side effects
initial? number handleNums 0 (line 113)

line 46 decimal, “.”, typeof ?? (There is no comment about this), line 79

state input next side effects
? “.” handleDecimal 0. (line 167)

line 47 zero, 0, typeof number? (There is no comment about this)

state input next side effects
? number handleNums .0 (line 113)

line 47 zero, 0, typeof number? (There is no comment about this)

state input next side effects
? number handleNums .0 (line 113)

Why (replace) ?

    crntN: this.state.crntN.replace('0','') + i,

This is a video of the process:

Cheers and happy coding :slight_smile:

1 Like

My guess would be because that’s what the FCC module on React uses?

I see :+1: .
I find functions easier to use in React(easier than classes).

Cheers and happy coding :slight_smile:

Wow you are awesome @erretres. I will fix my code and get back to you asap, Thank you very much!

  • Why did you use classes and not functions? I’m not saying that is wrong. There is a reason to not use functions?

I know that if the component will just render elements the function will be the shortest way, I guess it is just a habit or maybe like @bbsmooth said.

  • Your project has no comments, and because of that is really difficult to grasp the “shape” of your solution.

Well I think I underestimate them but when I started adding comments now I realize how sample my code is and I also found out that there is two unnecessary values in the component state, and there was a lot of “bugs” with the negative handler.

  • Your project at the moment can’t parse (handle) this input:
    0.000

Why ( replace ) ?

I used replace as a fast solution to stop the user from inputting many zeros but it ruined everything (now 0.1000, 1.000, 0.000 works great)

Check out my last adjustments, I used Github pages. React-calculator

Thank you for your time, your notes were very helpful.

Hi @houc.bh90,
Sorry for the delayed response, I have not been able to connect.

I see :+1:

I’m glad it helped :slight_smile:

Cheers and happy coding :slight_smile:

1 Like