0

This is about my js calculator

The problem is somehow hard to explain, For normal calculation,it has no problem.It works perfectly because of eval in js. But for complicated problem like permutation and combination,in which i have to write my own calculation code,once i have pressed the cancel button and try to perform e.g sine it still holds the previous answer and there fore giving me null e.g 3p2 will give me e.g 6 but then when I press ac whichwill clear my div I.e the place where my answer appears and I try sin 30 it gives me NaN. am thinking it is because it still considers that 6 from the previous answer and does 6sin30 so please who knows a way that when i clear the div,it clears any previous values I have written

2nd Jan 2019, 3:53 PM
Fakorede Damilola
5 Answers
+ 9
Using eval is dangerous and not recommended. If you eval 6 sin 30, it would be null. It must be 6 * Math.sin(30); just saying. Now to answer your question, variables carry values, so you must clear the variable. After a calculation, set all the variables used for displaying to 0 or null. Hard to tell without seeing your code, but that is the starting point
2nd Jan 2019, 4:37 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 8
Awesome! Well made Funny thing is i am not getting any errors or NaN. I tried everything and what you mentioned but still works :/
2nd Jan 2019, 4:54 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 8
linr 271 is the clearer. Looks ok. Try answer.splice(0, answer.length). using array=[] will not delete or clear any references to that array, so if it is referenced somewhere else, that is where you get the problem
2nd Jan 2019, 5:00 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
0
this is a link to the code I did not separate it cause it giving me an error when I do I don't know why https://code.sololearn.com/WPDRD00rPCQZ/?ref=app
2nd Jan 2019, 4:46 PM
Fakorede Damilola
0
no no at first it does not work but when you perform the first operation,and press ac I.e clear and you try another operation, it gives NaN if that operation is like P or r etc
2nd Jan 2019, 5:51 PM
Fakorede Damilola