Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Unchangable variable?

Hi all.

I used the function Math.max() to find the maximum number in a series of numbers. However, after it finds that number, I want it to say a specific thing if it is a certain number. Here's the code:

Code:
```var h = Math.max(a,b,c,d,e,f,g)
if (h==2){
h=="Two"
}```
However, when the maximum does turn out to be 2, it alerts ("2") instead of ("Two"). I've also tried this:

Code:
```var h = Math.max(a,b,c,d,e,f,g)
var l = "string"
if (h==2){
l=="Two"
}```
But on the alert, it comes back as "string". What's wrong here and what can I do to make this work?

• Hey,

Put
l="Two"
l=="Two"

Mike

• ## Users who have thanked Mike_O for this post:

CrackTheAir (06-02-2009)

• Thanks

• might want to consider using a look-up table instead of forks in a situation like this:

Code:
```var h = Math.max(a,b,c,d,e,f,g);
var labels="Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten".split(",");

• Originally Posted by rnd me
might want to consider using a look-up table instead of forks in a situation like this:

Code:
```var h = Math.max(a,b,c,d,e,f,g);
var labels="Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten".split(",");

That does not work! labels[h] is the maximum value of the list, (say 99), not the index of that value.

Suggest:-

Code:
```<script type = "text/javascript">

var a = [5,26,4,96,7,24,45,38,52];
var index;
var max = a[0];
var maxIndex = 0;
for (index = 1; index < a.length; index++) {
if (a[index] > max) {
max = a[index];
maxIndex = index;
}
}

alert ("Maximum value is " + max + " at array index " + maxIndex);
var labels="Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten".split(",");