0% found this document useful (0 votes)
13 views7 pages

Loop Practice Question

Uploaded by

animezzb69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views7 pages

Loop Practice Question

Uploaded by

animezzb69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Review Question e(total) varN=1 while (N <= 32 N=2°N. document.write(N + ) } (d) varx=5,y=1; while (x > 0) { x=x-1; yey "x; document.write(y +""); } (e) var U= 10, V= 20; for (1 = 1; 1 <= 2; I++) { 7 document.write("(1]="+U+++" &"+V+5+ "
"); document.write("[2]="+++V +" &"+U +2); } 10. What is the output of the following program segment? (a) |=0; for (i = 1; i <= 20; i++) { document.write(i+""); [=al+2; } (6) i=0,x=0; while (i < 10) { if ((1 % 2) == 0) { xX=x+1; 2022/5/2 22:58 yoor™™™ it 13. 14, 15. 16, 17, document. write(x +") } Find the error, if any, in the f - mae he following program: while (w>60) { r=w-S0; switch(w) { 20 : document. write("Lower Range") 30; document.write("Middle Range"); a : document.write("Higher Range"); } . What is wrong with the following code fragment? What are the three disti to remove the flow? count = 50 while (count >= 0) { document.write(count +""); count = count + 1; } What is the output of the following code? index = 1; do { document.write(index+""); index++; } while (index < 10); What is the output of the following code? index = 1; do { document.write(index +""); } while (index < 10); Write the following code using a do loop: var index = 1; while (index < 10) { document.write(index +""); index ++; } Write the following code using a for loop: var index = 1; while (index < 10) { document.write(index +"); index ++; } . What is the output of the following code? var NUM=12345; ee 19, 20. 21. var Rem=0, F=0, $=0, T do { Rem = NUM%10; if (Rem % 2 l= 0) F+=Rem. else St=Rem; NUM/=10; }while (NUM>0); T=F-S; document.write(T); : - What does the following program code display? var a, b= 1, sum =0; while (b <= 10) { a=b*b; document.write(a + "
"); sum += a; +b; } document.write("Total is" + sum); Give the proper array declaration for the following: () Declare an array Wages which can hold 25 values (ii) Declare an array Student which can hold 4 values. (iii) Define an NArr empty array. Write the value of individual array element: (i) varc=(2, 7,9, 6, 1,4, 3, 8] (i) var p=newArray(1, 1, 3,3, 5,5, 7, 7) Write a JavaScript program to perform the following tasks Read an array of 10 number. Multiply each element of array by 5, ‘Display the new array. Write a JavaScript program to print numbers from 1 to 10 a statement. Using Javascript, write a for loop that will print out all the 1821 24273033 36. Write a program to find the greatest common divisor of t Write a for loop to find sum and average of n natural nu Write a JavaScript for loop to print out the values 1 to 1( Write a JavaScript for loop which will produce the follo 1 Ss an Mult! 3.136 20. 21. 22 23 24, 5. 6. 7, var Rem=0, F=0, $#0, T; do { Rem = NUM%10; if (Rem % 2 l= 0) F+=Rem; else S+=Rem; NUM/=10; }while (NUM>0); T=F-S; document.write(T); ; 5 What does the following program code display? var a,b=1, sum =0; while (b <= 10) { a=b*b; document.write(a+"
"); sum += a; ++b; } document.write("Total is" + sum); Give the proper array declaration for the following: (4) Declare an array Wages which can hold 25 values. (ii) Declare an array Student which can hold 4 values. (iii) Define an NArr empty array. Write the value of individual array element: () varc=[2,7,9,6, 1,4, 3, 8] (ii) var p=new Array(1, 1,3, 3,5, 5, 7,7) Write a JavaScript program to perform the following tasks: Read an array of 10 number. Multiply each element of array by 5. Display the new array. Write a JavaScript program to print numbers from 1 to 10 an statement. Using Javascript, write a for loop that will print out all the ; 18 21 24273033 36, Write a program to find the greatest common divisor of ty Write a for loop to find sum and average of n natural nun Write a JavaScript for loop to print out the values 1 to 10 Write a JavaScript for loop which will produce the folloy 1 22 ping in davascript 00 Ww a variat al :. om the ann ry Positive real numbers entered by the 1 100 nlieat tothe largeet. The user wil Pome ns Mill a most 100 ser will input a zero to mark the . 100 positive numbers will be -_s avaScript code to find all the duplicate aes be ente F a: ¢ duplicate elements in an ar 3. Write a JavaScript for loop to print out th uke i pt ‘nt out the character set from A to Z # x error(s), if any, in the following JavaScrip seca ne javaScript program var x y = 15; x=5 for (= 0; 1 < 10; ++i) If (i = x) break, document.writ(y); document.write(x y); + 34. Give the output of the following JavaScript program segment: 35. Give the output for the following JavaScript program segment: (a) for(var| = 10; | > 6; | = I-2) document.write(i + "
"); (6) for(var i = -5; | < -8; I- -) document.write(i + "
"); (c) for(var | = -3, sum = 0; | < 11; |++) sum++; document.write(sum) 36, Find the output of the following JavaScript code: (a) a=1; b=5; b++; if(b == 5) ae document.write("value Is five"); else r document.write("value Is not five"); (6) varl = 1; 2022/5/2 é swatt Multimec ’ hne 3.138 a “tea What will be the value of y when the loop is executed for the first tim lowing JavaScript example, what is the final value ¢ f (x == 4) continue; 2022/5/2 23:00 ) enohin In Javas 2, Find the } else 13. Whatis wrong with the it produces correct output : le fir 4 . if (total == max c hi if (total < sum document.writertoe else ; document write(“total eae 14, Rewrite the following switch statemu oe 12! €© MAX te ent using if-else statement case 1: document.write(“digires case 100: document write"trny rei, case 1000 3 an document. write("thoy ands"); break case 10000: document.write("ten thousands default: document. write(“error’) ile a 15. An electronic shop has announced the following seasonal discounts on the purchase of certain ite pecs’ Amount (7) Discount (%)on Laptop | Discount (%) on Desktop PC | 0-25,000 00 | 50 25,001 ~ 57,000 50 75 57,001 — 1,00,000 15 100 | More than 1,00,000 10.0 150 Write a JavaScript program based on the above criteria, to input amount of purchase and the type of purchase (Laptop or Desktop) by a customer, Compute and print the net amount to be paid by a customer along with his name and address (discount rate / 100) * amount of purchase Net amount (Hint: discount amount of purchase discount), Write a JavaScript program that asks the user to enter two integers, obtains the numbers from the use and displays the larger number followed by the words “is larger” in an alert message dialog. If th numbers are equal, print the message “These numbers are equal N fo} Nn Nn ee a = I} IN} w oO

You might also like