How can I add square root in a calculator which will only take the input value after the square root symbol by using JS? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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!!!!

2nd Jan 2020, 2:22 PM
Sayem
Sayem - avatar
8 Respuestas
+ 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().
2nd Jan 2020, 7:59 PM
Jianmin Chen
Jianmin Chen - avatar
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.
2nd Jan 2020, 7:47 PM
Jianmin Chen
Jianmin Chen - avatar
0
I tried it already & faced the problem....
2nd Jan 2020, 7:50 PM
Sayem
Sayem - avatar
0
I can make the sqrt button but i have to first evaluate the whole calculation and then do the square root
2nd Jan 2020, 7:52 PM
Sayem
Sayem - avatar
0
Could u please check this
2nd Jan 2020, 8:03 PM
Sayem
Sayem - avatar
0
Please see my calculator
2nd Jan 2020, 8:09 PM
Sayem
Sayem - avatar
0
Can you edit it please...
2nd Jan 2020, 8:10 PM
Sayem
Sayem - avatar