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: ________________
answer: ________________
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: ________________
var end = 5; var res = 10; var k ; for (k = 2; k < end; k++) { res = res + (k*k) ; } alert(res); answer: ________________
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: ________________
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: ________________
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: ________________
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: ________________
(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: _____________________
(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) _______ slow non-volatile storage ii) _______ grouping of variable locations in a program that can be systematically used by subscript iii) _______ single datum of binary information: 0 or 1 iv) _______ basic data type in JavaScript that comprises exactly two values v) _______ place where all arithmetic operations are performed in the computer vi) _______ abstraction of a sequence of program statements that can be run by naming it and passing arguments vii) _______ repetition where we dont know in advance how many times we need to repeat a task viii) _______ basic collection of 8 binary data values ix) _______ combination of values and variables with operators that reduces to a value under control of precedece rules x) _______ fast volatile main storage
(A) terminator (B) counter (C) accumulator (D) indicator (E) declarator answer: _____________________
(A) precedence rules (B) switch statement (C) function call (D) cascading conditional (E) scope rules answer: _____________________
i) ________ Math.round(23.77318); ii) ________ Math.floor(23.77318); iii) ________ Math.sqrt(16); iv) ________ 18 % 5 v) ________ isNaN("javascript"); vi) ________ isNaN(25); vii) ________ true && false viii) ________ !true || !false ix) ________ Number("-225"); x) ________ 4 + 5 * 2 xi) ________ 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: _____________________
(A) x += 1 ; (B) x++ ; (C) x = x + 1 ; (D) x % 1 ; (E) ++x ; answer: _____________________