+ 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.
5 Antworten
+ 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
+ 2
alert(eval("1+2*3-3/4"));
0
Will try this out. thank you
0
Will try this also sir. thank you
- 1
@Andre Harchenko sir thank you so much for your answer. I will try this in my code. thank you. God Bless!