+ 1

# Need explanation!

Can somebody tell me how this codes executed? function t(n) { while (n < 5) { n++; } return n; } alert (t(2));

2 Answers

+ 4

In plain English: "Take an input n, and keep incrementing it by 1 until it's at least 5."
So, you give that function 2. 2 is less than 5, so it keeps adding 1 until n is 5. Then it returns the result, which will be 5 in this case.
So, for any input less than or equal to 5, it will return 5. For everything else, it will return the input you gave it.

0

Thanks guys...
This code is popping 5...
So @Squidy is more make sense...