I've been given a couple simple tasks for an evaluation that I'd like to verify.
1) The first is :
Please implement a JavaScript function called “thisisaloop” that initializes a variable called ‘dl’ with a value of ‘0’ and uses a for loop to increment the value of ‘dl’ by 1 on each iteration. Allow the for loop to execute until ‘dl’ possesses a value of ’10’, then have the function return the value of the ‘dl’ variable.
Here is my answer- will this work?
function thisisaloop()
{
var dl=0;
for (var i=0;i<10;i++)
{
dl=dl+1;
}
return dl
}
2) The second is to point out the errors in a JavaScript below. It is meant to run a while loop that adds 1 to the value of the 'dl count' variable upon each iteration, then returns the value of 'dl count' when the value reaches 100.
Line #
01 <script type="text/javascript">
02 var result = dlRules(0);
03
04 function dlRules (dl_count) {
05 var limit = 100;
06 match = 1;
07
08 while (dl_count != limit)
09 dl_count ++ match;
10 if (dl_count == 95) {
11 dl_count = 10;
12 }
13 }
14 return (dl_count)
15 }
16 </script>
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.