This exam is closed book, closed notes, closed computer, closed classmates,
closed everything.
Please put all answers on the test sheets.
Make sure your answer is clearly marked and easily distinguished
from work you do to get to the solution.
You should show your work for partial credit.
When done, please staple together your exams sheets and any paper
you use for work and place it face down on the lecture table.
Please please print your name
clearly below, and sign when you hand in the exam,
signifying your adherence to
the honor code and attesting to the work being yours alone.
Name (print) _____________________________________________________________________ Signed __________________________________________________________________________
answer: ___ 11001101 ______
answer: ___ 182 ______
var top = 9; var num = 4; var i = 3; var done = false; while (!done) { num = num + i; i = i + 3; if (i > top) { done = true; } } alert(num); answer: ___ 22 _________
var end = 5; var res = 10; var k ; for (k = 2; k < end; k++) { res = res + (k*k) ; } alert(res); answer: ___ 39 _________
var a = 4; var x = 10; if ( x < 10 ) { x = x - 3; a-- ; } else { x = 22 - a ; a = a*2 ; } if ( a <= 0 ) { a = a + 4; } else if ( a == 4 ) { a = a - 10 ; } else if ( a > 7 ) { a = a * 2; } else { a = -8; x = 12; } if ( x >= a ) { x = x - a ; } alert("a: " + a + ", x: " + x); answer: __ a: 16, x: 2 _____
var tag = 5; var val = 2; tag = tag-val; switch (tag) { case 0: val = 5; break; case 1: val = val + 4; break; case 2: val = val / 3; break; case 3: val = val * 2; break; case 4: val = val - 1; break; case 5: val = val * tag; break; } alert( val ); answer: ___ 4 __________
var high = 4; var arr = [ ]; var j; arr[0] = 1; for (j=1; j <= high; j++) { arr[j] = arr[j-1] * j + 2 ; } alert( arr[3] ); answer: __ 26 __________
function main() { var max = 5; var tot = 10; tot = 2 * mash ( max ); alert("tot: " + tot + ", max: " + max); } function mash ( tot ) { var tweak = 7 ; var res = -2 ; res = (tot + tweak) * res ; tot = 12; return res; } answer: __ tot: -48, max: 5 _____
(A) loops and repetition (F) data abstraction (B) conditionals (G) browser (C) prompt box (H) expressions and data retrieval (D) HTML (I) procedure abstraction (E) variables and assignment (J) JavaScript answers: __ C, D, G, J ______
(A) byte (G) world wide web (M) CPU (or ALU) (B) internet (H) output (N) definite loop (C) string (I) RAM memory (O) gigabyte (D) function (J) indefinite loop (P) expression (E) bit (K) integer (Q) input (F) array (L) disk (R) booleanFor each of the following definitions, select the item above that best matches (put the corresponding letter in the blank):
i) __ L __ slow non-volatile storage ii) __ F __ grouping of variable locations in a program that can be systematically used by subscript iii) __ E __ single datum of binary information: 0 or 1 iv) __ R __ basic data type in JavaScript that comprises exactly two values v) __ M __ place where all arithmetic operations are performed in the computer vi) __ D __ abstraction of a sequence of program statements that can be run by naming it and passing arguments vii) __ J __ repetition where we dont know in advance how many times we need to repeat a task viii) __ A __ basic collection of 8 binary data values ix) __ P __ combination of values and variables with operators that reduces to a value under control of precedece rules x) __ I __ fast volatile main storage
(A) terminator (B) counter (C) accumulator (D) indicator (E) declarator answer: ___ B _____________
(A) precedence rules (B) switch statement (C) function call (D) cascading conditional (E) scope rules answer: ___ E _____________
i) __ 24 ___ Math.round(23.77318); ii) __ 23 ___ Math.floor(23.77318); iii) __ 4 ____ Math.sqrt(16); iv) __ 3 ____ 18 % 5 v) _ true __ isNaN("javascript"); vi) _ fasle _ isNaN(25); vii) _ fasle _ true && false viii) _ true __ !true || !false ix) _ -225 __ Number("-225"); x) __ 14 ___ 4 + 5 * 2 xi) __true __ 1 > Math.random() Note: what we are asking is what would be printed if the expression was in an alert statement... for example, for questions (vii), what would get printed for alert( true && false )
(A) terminator (B) counter (C) accumulator (D) indicator (E) declarator answer: __ C ______________
(A) x += 1 ; (B) x++ ; (C) x = x + 1 ; (D) x % 1 ; (E) ++x ; answer: __ D _______________