# txtDisplay.text = num1+expression+num2;

**URL:** <https://forum.kirupa.com/t/txtdisplay-text-num1-expression-num2/42255>\
**Category:** flash\
**Created:** [February 6, 2004, 10:19pm UTC](https://forum.kirupa.com/t/txtdisplay-text-num1-expression-num2/42255 "2004-02-06T22:19:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jigsaw1975](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jigsaw1975](https://forum.kirupa.com/u/jigsaw1975)\
**Post date:** [February 6, 2004, 10:19pm UTC](https://forum.kirupa.com/t/txtdisplay-text-num1-expression-num2/42255/1 "2004-02-06T22:19:04Z")

</div>

FYI: This is a calculator.

I am trying to figure out how to do it in this very method and nothing else. (Please do not suggest if statements or case statements. Thanks)

Example  
when someone clicks on button 1, num1=1;  
then they will click on the +,-,\* or / button  
so expression variable will be set to = “/” or “+” or “-” or “\*”  
then they would choose the next integer.  
lets say button 2, num2=2

so now we have values for num1,expression,num2

I have already parseInt num1 and num2

i want txtDisplay.text = num1+expression+num2;

But it is showing up on the textbox as 1+2; //if add was chosen

I hope I am making myself clear

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 10:31pm UTC](https://forum.kirupa.com/t/txtdisplay-text-num1-expression-num2/42255/2 "2004-02-06T22:31:42Z")

</div>

whats the code on button1?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 11:18pm UTC](https://forum.kirupa.com/t/txtdisplay-text-num1-expression-num2/42255/3 "2004-02-06T23:18:20Z")

</div>

Welcome, jigsaw. 🙂

How about something like this?

```auto
var equations = new Object();
equations["+"] = function (a, b) {
	return a+b;
};
equations["-"] = function (a, b) {
	return a-b;
};
equations["*"] = function (a, b) {
	return a*b;
};
equations["/"] = function (a, b) {
	return a/b;
};
var e = "*";
var n1 = 2;
var n2 = 2;
var r = equations[e](n1, n2);
trace(r);

```

…I honestly don’t think there’s another way, since you don’t want to use [font=courier new]if[/font] or [font=courier new]switch[/font] statements. :-/
