0
How can I add square root in a calculator which will only take the input value after the square root symbol by using JS?
I want to say that if in a calculator.. suppose I input '5+6+√9+6'..... So the calculator should take the square root of 9 only and add all the constituents..... Please help me in this by using JavaScript!!!!
8 odpowiedzi
+ 1
Perhaps you can split the input using .split(), which converts the input into a list:
input.split("+")
This basically splits the strings into a list and removes the "+"(you told us in the post you were only trying to add). Then you can take the items in the list, go through them using a for loop, convert them to integers using parseInt(). You can loop through the numbers, and add them to a variable. If they involve a square root, then you can use Math.sqrt().
0
You should try on your own, and provide the code, before asking for help. But here's a hint:
The function Math.sqrt(//number) returns the square root of the number provided.
0
I tried it already & faced the problem....
0
I can make the sqrt button but i have to first evaluate the whole calculation and then do the square root
0
Could u please check this
0
Please see my calculator
0
Can you edit it please...