How to show all basic computation (+ - * /) in one alert? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to show all basic computation (+ - * /) in one alert?

User will input two numbers then after he submit it, an alert window will display all the basic computations. output: ans = x + y; ans = x - y; ans = x * y; ans = x / y; in one alert window.

21st Aug 2017, 4:44 AM
michaey tenorio
5 Answers
+ 6
alert("x + y = " + (x + y) + "; x - y = " + (x - y) + "; x * y = " + (x * y) + "; x / y = " + (x / y) + ";"); I think you don't really need to name each result an "ans", right? Else you can change each "describing" string to an "ans = " (and "; ans = ") And if x and y are just entered by user and are still considered by Javascript as strings than you may need to change first "evaluation" from (x + y) to (+x + +y). Here is an example: https://code.sololearn.com/Wv30rtJh2gjF/?ref=app
21st Aug 2017, 5:20 AM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 2
alert(eval("1+2*3-3/4"));
21st Aug 2017, 5:03 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
0
Will try this out. thank you
21st Aug 2017, 5:17 AM
michaey tenorio
0
Will try this also sir. thank you
21st Aug 2017, 5:21 AM
michaey tenorio
- 1
@Andre Harchenko sir thank you so much for your answer. I will try this in my code. thank you. God Bless!
21st Aug 2017, 1:57 PM
michaey tenorio