Page 336 - Web Applications (803) Class 11
P. 336

Ð ÐNever leave the terminating condition to the user’s discretion: The user may thoughtlessly cancel the prompt box
                 etc. which may prevent the loop from terminating.


                                               Lab Assignment ‘n Activity                         Experiential Learning




                 1.  Predict the output of the following code:
                     <html>
                     <body text=”green”>
                     <h2>Using do...while loop in JavaScript</h2>
                     <script>
                     /* to find the sum of positive numbers entered by user. The loop terminates when
                     the user enters a negative number,and that negative number is not added to the
                     sum */
                     var sum = 0;
                     var number = 0;
                     do {
                         number = parseInt(prompt(“Enter a number: “));
                         sum=sum+number;
                     } while(number >= 0);
                     document.write(“The sum is “+sum);
                     </script>
                     </body> </html>
                 2.  What will be the output of the following code?
                     <html>
                     <body text="red">
                     <h2 style="color:blue;">Using the for...in loop</h2>
                     <script>
                     var string1="Artist";
                     for (i in string1) {
                       document.write("<br>"+ string1[i]);
                     }
                     </script>
                     </body>
                     </html>
                                                                                                       Critical Thinking

                        Video Session


                   Scan the QR code or visit the following link to watch the videos: #12 JavaScript Tutorial | While loop -
                   https://www.youtube.com/watch?v=osOEz3SwyVk
                   Now try out the same program shown in the video (display first 5 odd numbers) on your own using a while loop

                   Watch the video #13 JavaScript Tutorial | Do While loop -
                   https://www.youtube.com/watch?v=zGG56ae5_GM
                   ............................................................................................................................................................................................
                   ............................................................................................................................................................................................





                334     Touchpad Web Applications-XI
   331   332   333   334   335   336   337   338   339   340   341