+ 2
Code comparison & explanation
MY the first code doesnt work and the difference to the revised version is just the location of where the variables was declared. the first one was on the first lines and the second one was inside a function. can someone explain why this happens? thank you https://www.sololearn.com/compiler-playground/WsQQtVzSMADI/?ref=app
2 Réponses
+ 4
Firstly, make your code public and then, you can see '+' icon right side click on, then click insert code, and you can see on top 'hot today' drop-down menu and click on my code bits then share it
0
Line 26 invokes the inputs function before the user inputs any value.
Because of this, when called, the inputs function returns NaN.
Meaning that back at line 26, the variables ef, radius, and angle are all assigned NaN.
The inputs function is never invoked after the submit button is pressed.
So when the user does enter any values, the variables(ef, radius, angle) are not updated.
And the initial values(NaN) are used in the formula() code block resulting in NaN as output.