please explain answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

please explain answer

The following code will result in what value? function test(number) { while(number < 5) { number++; } return number; } alert(test(2));

21st Aug 2017, 5:18 PM
aman tyagi
aman tyagi - avatar
3 Answers
+ 12
Function test accepts a number as a parameter and increments it while the number is smaller than 5. The function returns the number after the loop ends. Hence, the function will always return 5 for values smaller than 5. alert(test(2)) will result in output of 5.
21st Aug 2017, 5:27 PM
Hatsy Rei
Hatsy Rei - avatar
0
5
7th Jul 2022, 9:50 AM
Sumat Singh
Sumat Singh - avatar
0
The code below the result Counter =0 While counter<4: Print( counter)
13th Feb 2024, 5:58 AM
Manoranjitham S R
Manoranjitham S R - avatar