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

Thread: How to determine which number is highest, surprisingly hard!

1. How to determine which number is highest, surprisingly hard!

Okay, I've got three variables: highPercent, mediumPercent, and lowPercent. The following code checks them to find the highest:

Code:
```var highest = 100;
if (highPercent >= mediumPercent && highPercent >= lowPercent) { highest = highPercent; }
if (mediumPercent >= lowPercent && mediumPercent >= highPercent) { highest = mediumPercent; }
if (lowPercent >= mediumPercent && lowPercent >= highPercent) { highest = lowPercent; }```
But with the following values:

High: 29
Medium: 64
Low: 7

It decides that High is the largest of the three.

Why?

• Code:
```function max() { (arguments.slice = Array.prototype.slice)
if (arguments.length == 2)
return (arguments[0] > arguments[1]) ? arguments[0] : arguments[1];
else
return max(arguments[0], max.apply(max, arguments.slice(1)));
}```
max(lowPercent, mediumPercent, highPercent)

should return the correct one.

Edit: Leave it to me to forget about the built-in Math.max() function.... Math.max(lowPercent, mediumPercent, highPercent)

• doesn't max only take two values tho?

• I don't think so, try the following

<script>
</script>

• oh yeah, so it does!!

•

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•