+ 6
I don't understand why the output is 5, Here please explain thanks
The following code will result in what value? function test(number) { while(number < 5) { number++; } return number; } alert(test(2));
18 Respostas
+ 15
In your example , you enter while 2<5 --> True, 2++---> number is 3 , 3<5 ---> True , 3++ --> number is 4, 4<5 --> True , 4++ ---> number is 5. 5<5 ---> FALSE , exit WHILE. So number is 5
+ 13
Because while number is less then 5 variable will increment. It will reach 5 and stop.
+ 4
First you will call alert(var1) that calls your function test(var2) and sends var2 ( in your example 2) to this function as argument. In function test you have while loop which you can look in 3 steps. STEP 1: Ask condition (number < 5) and if FALSE exit while, and if TRUE then STEP 2: execute statements ( you have only number++) and STEP 3: Loop again to STEP 1.
+ 3
A box will pop-up containing the return value of number (witch is based on the arguments you pass (here you pass 2))
+ 3
the "alert(test(2))" means that you want to create an alert window that will show the the result (the returned number) when the test function is run with a 2 passed in as the parameter.
+ 2
ok thanks what does the alert(test(2)); mean?
its mean that your function start from 2
function test(number) = function test(2)
+ 1
In your example , you enter while 2<5 --> True, 2++---> number is 3 , 3<5 ---> True , 3++ --> number is 4, 4<5 --> True , 4++ ---> number is 5. 5<5 ---> FALSE , exit WHILE. So number is 5
+ 1
The following code will result in what value?
function test(number)
{
while(number < 5) {
number++;
}
return number;
}
alert(test(2));
Answare == 5
0
ok thanks what does the alert(test(2)); mean?
0
Thank You Druide for the explanation
0
thanks for the explination
0
yeah the output is five
0
thanks
0
5
0
5
0
The answer will be 5
- 1
5
- 1
5