Can anyone help me by evaluating this code?

This is the question:
‘‘Write a program that reads two real numerical values ​​represented by variables A and B. Calculate, store and present the result of the four basic arithmetic operations.’’

is everything in order?
Is there any way to reduce the code further?
help me please. :slightly_smiling_face: :blush:

Hi @Phellipe_ferreira :wave:

Some improvements:

  • There’s currently a ReferenceError because you first used “sum” and later “soma”.
  • Consider replacing parseInt() with parseFloat() to make the app work with decimal numbers, too.
  • Use parseFloat() in the definition of A and B to not having to repeat it for every operation:
    let A = parseFloat(inputA.value);
    let B = parseFloat(inputB.value);
    
  • It’s good to check, if we’re really dealing with numbers, but your condition is wrong. With the above changes it should be if (!isNaN(A) && !isNaN(B)) {

I hope that helps. :slightly_smiling_face:
Michael

2 Likes

ooh thank you, helped me a lot. :smiley: :clap:

1 Like