[PDF] [PDF] COMP 110 Practice Exercises for Midterm – Solutions

Write javascript code to do the following 16 Alert "Hello world " alert("Hello world "); 17 Read a 



Previous PDF Next PDF





[PDF] Automatic Assessment of JavaScript Exercises - CEUR-WSorg

answer was that JS is too ugly and confusing Products like GMail and Facebook rely heavily on JS, there are many good tools for professionals (examples in 



[PDF] COMP 110 Practice Exercises for Midterm – Solutions

Write javascript code to do the following 16 Alert "Hello world " alert("Hello world "); 17 Read a 



[PDF] JavaScript Lab Assignment 1 Figure: Snap shot of the solution We

Figure: Snap shot of the solution EE1081 JavaScript Assignment 1: Instruction: 1 Complete the code where there are *** with JavaScript and HTML code to



[PDF] Exercises related to HTML, CSS, and JavaScript - Karis site for

4 nov 2018 · Mostly these exercises deal with JavaScript programming • To do these exercises, you need an editor and a web browser The editor should be 



[PDF] LearnJS - A JavaScript Learning Playground - DROPS - Schloss

On the other hand, learners can solve exercises and receive immediate feedback on their solutions through static and dynamic analyzers Since we are in the early  



[PDF] JavaScript Exercises - Cartography & GIS Lab

JavaScript Exercises GEOG 3530/8535 Cartography GIS UNO -‐ Peterson 7- 1 html document write("Hello 



[PDF] (JavaScript) - NCERT

Some people think that Java and JavaScript are same but both are and online gaming are examples of client-server model INDIA Alert about answers of the



[PDF] Plug-In JavaScript: 100 Power Solutions

viii Plug-in JavaScript: 100 Power Solutions Plug-in 3: NOTE I have used single quotation marks in these examples but JavaScript allows you to use either



[PDF] Chapter 15 JavaScript 4: Objects and Arrays

Answer the following questions about the weekDays array: The above examples illustrate that arrays can either be created separately (as in VERSION 1 ), and 



[PDF] JavaScript FOR KIDS JavaScript FOR KIDS

You'll find sample solutions to the programming challenges (as well as the code files for the games and other examples) at http:// nostarch com/javascriptforkids/

[PDF] javascript based applications

[PDF] javascript bible 2019 pdf

[PDF] javascript bible 7th edition pdf

[PDF] javascript book pdf

[PDF] javascript console acrobat pro

[PDF] javascript design patterns 2019

[PDF] javascript desktop application

[PDF] javascript editor in pdf

[PDF] javascript events notes pdf

[PDF] javascript events with examples pdf

[PDF] javascript examples bible pdf

[PDF] javascript for acrobat api reference

[PDF] javascript for adobe acrobat

[PDF] javascript for adobe acrobat api

[PDF] javascript for adobe acrobat dc

1

Answersarehighlightedinbluecolor.

Evaluateeach

1. Ͳ9*3Ͳ27

2. "valueis"+50"valueis50"

3. 17%52

4. 5%175

5. 5/100.5

6. (4==4)true

7. (4!=5)true

8. (7<=8)true

9. Math.ceil(x)ͲMath.floor(x)1

10. 11011155

11. 10101143

12. 10100

20

13. 55110111

14. 43101011

15. 20

10100
Writejavascriptcodetodothefollowing.16. Alert"Helloworld." alert("Hello world");

17. Readanumber(using

prompt)anddisplayitusingalert. var n = prompt("Please enter a number."); alert("Your number is "+ n);

18. Readtwonumbersanddisplaytheirproduct.

var n1 = prompt("Please enter a number."); 2 var n2 = prompt("Please enter another number."); alert("The product of "+n1+" and "+n2+" is "+ n1*n2);

19. Readtwonumbersanddisplaytheirsum.Whatproblemdidyouencounter?

var n1 = 1*prompt("Please enter a number."); var n2 = 1*prompt("Please enter another number."); alert("The sum of "+n1+" and "+n2+" is "+ n1+n2); promptreturnsastring.

20. Readintwonumbersanddisplaythelarger.

var n1 = 1*prompt("Please enter a number."); var n2 = 1*prompt("Please enter another number."); if (n1 > n2) alert(n1+" is the larger."); else alert(n2+" is the larger."); If thestring"100".

21. Readintwonumbersanddisplaytheminascendingorder.

var n1 = 1*prompt("Please enter a number."); var n2 = 1*prompt("Please enter another number."); if (n1 > n2) alert(n2+" "+n1); else alert(n1+" "+n2);

22. Usealooptodisplaythenumbers0through5,eachinaseparatealertwindow.

for (var i=0; i<=5; i++) alert(i);

23. Usealooptodisplaythenumbers0through5inasinglealertwindow.

3 var s=""; // Create empty string. for (var i=0; i<=5; i++) s = s + i + " "; // Add next integer plus a space. alert(s);

24. Usealooptodisplaythenumbersintherange0...20thataremultiplesof3.

// Solution 1: Generate all numbers and test each. for (var i=0; i<=20; i++) if (i%3==0) alert(i); // Display those that are // divisible by 3. // Solution 2: Generate only multiples of 3. for (var i=0; i<=20; i=i+3) alert(i); // Only multiples of 3 are generated.

25. Usealooptodisplaytheintegers9through0indescendingorder.

for (var i=9; i>=0; i--) { alert(i);}

26. Prompttheuserforanumberinthe

// Solution 1: Put the test in the while statement. var n = prompt("Please enter a number in the range 0...100"); while (n<0 || n>100) alert(n +" is out of range. Try again."); n = prompt("Please enter a number in the range 0...100"); 4 // Solution 2: Put the test inside the loop. while (true) var n = prompt("Please enter a number in the range 0...100"); if (n>=0 && n<=100) break; alert(n +" is out of range. Try again.");

27. Repeatpreviousexercise,butthistimeallowforthepossibilitythattheuserenterssomethingthatisnota

number.Sortofbackwards, butthat'swhat'savailable. // Solution 1: put the test in the while statement. var n = prompt("Please enter a number in the range 0...100"); while (isNaN(n) || n<0 || n>100) alert(n +" is out of range or not a number. Try again."); n = prompt("Please enter a number in the range 0...100"); // Solution 2: put the test inside the loop. while (true) var n = prompt("Please enter a number in the range 0...100"); if (!isNaN(n) && n>=0 && n<=100) break; alert(n +" is out of range or not a number. Try again.");

28. Promptforaninteger,thendisplaythesumoftheintegersfrom0throughthenumberentered.For

+4+5+6+7+8+9+10. // Get the upper bound. var max = 1*prompt ("Please enter an integer."); var sum = 0; for (var i=0; i<=max; i++) 5 sum = sum + i; // Add i to the running sum. alert("The sum of 0 through "+max+" is "+sum);

29. Promptforaninteger,thendisplaytheaverageoftheintegersfrom0throughthenumberentered.For

+9+10)/11. // Get the upper bound. var max = 1*prompt ("Please enter an integer."); var sum = 0; for (var i=0; i<=max; i++) sum = sum + i; // Add i to the running sum. alert("The average of 0 through "+max+" is "+(sum/(max+1)));

Writeafunctiontodoeachofthefollowing.

30. greet();displays"Helloworld"

function greet() alert("Hello world");

31. sum(n);displaysthesumof0+1+2+...+n.

// Sum the integers 0...n. function sum(n) var tot=0; for (var i=0;i<=n;i++) tot=tot+i; alert("The sum of 0 through "+n+" is "+tot);

32. isValid(n)returnstrueifnisanumber0...100.

// Is the parameter between 0 and 100? function isValid(n) { // Restriction: none // Errors checked for: n not a number; 6 // n out of range. if (isNaN(n)) return false; // Not a number. return n>=0 && n<=100; // Range test.

33. isInteger(n)returnstrueisnisaninteger0...100.Hint:useisValid.

// Is n an integer in 0 ... 100? function isInteger(n) { // Restriction: none // Errors checked for: n not a number; n out of range; // n not an integer. if (!isValid(n)) return false // Not a number or out of range. // If we get to this point, n must be a number in range. return (Math.floor(n)==n) // Integer test.

Codetracing:

34. Tracethefollowingcodebyshowingthevaluesofthe3variablesinthetableontheright,foreachlineof

codethatisexecuted (afterthelineisexecuted): // Start of execution var x = 5; var y = 10; var z = 7; x = (y+z)/2; y = 8; z = (x-y)/2;

35. Tracethefollowingprogrambyshowingthetextofthealertmessagesthataredisplayedwhenitruns.

Therearenoerrors.

// Start of execution x y z

5 Undefined Undefined

5 10 Undefined

5 10 7

8.5 10 7

8.5 8 7

8.5 8 0.25

7 var x =5; var y =1; while (x > 0){ x = x-1; y = y*x; alert(x + " " + y); 4 4 3 12 2 24 1 24 0 0 var i; var count =0; for (i =0; i < 11; i++){ if (i < 3 || 7 0 range 1

1 range 1

2 range 1

2 range 3

3 range 3

8

4 range 3

5 range 2

5 range 3

6 range 3

8 range 1

9 range 1

10 range 1

36. Whatistheoutputdisplayedbyeachofthefollowingcodefragments?

for (var i=0; i<10; i++) alert(i);

10alertswiththevalues0...9.

for (var i=10; i<10; i++) alert(i); for (var i=10; i>=0; i--) alert(i)

11alertswiththevalues10downto0.

for (var i=0; i<5; i++) for (var j=0; j<3; j++) alert(i +" "+ j);

15alertswiththefollowing

values. 9 00 01 02 10 11 12 20 21
22
30
31
32
40
41
42
loop. for (var i=0; i<5; i++) for (var j=i; j<5; j++) alert(i +" "+j); 00 01 02 03 04 10 11 12 13 14 22
23
24
33
34
44

37. Whatdoesthiscodedo?

var count=0; for (var half=0; half<=2; half++) { for (var qtr=0; qtr<=4; qtr++) { for (var dime=0; dime<=10; dime++) { for (var nick=0; nick<=20; nick++) { for (penny=0; penny<=100; penny++) { if (50*half + 25*qtr + 10*dime + 5*nick + penny == 100) { count++; } alert(count); $1.00.quotesdbs_dbs14.pdfusesText_20