Studying for Quiz 3
Quiz 3 is all about programming, so I want to make sure that you’re reviewing and understanding the concepts as you go. Given what we have covered, you should be able to answer the following questions now (review the past few lectures if you’re confused on these concepts or come to office hours)...
1
Topics
2
Arithmetic Operators
Consider the following:
let result = 9 % 2;
1. What is the VALUE stored in result?
2. What is the DATA TYPE of the value stored in result?
3
Arithmetic Operators
Consider the following:
let result = 9 / 2;
1. What is the VALUE stored in result?
2. What is the DATA TYPE of the value stored in result?
4
Arithmetic Operators
Consider the following:
let a = 4 ** 2;
let result = a / 2;�
1. What is the VALUE stored in result?
2. What is the DATA TYPE of the value stored in result?
5
Functions
function f1(a, b) {
return a * b;
}
function f2(a, b) {
return b - a;
}
let x = f1(2, 3);
let y = f2(1, x);
let z = f2(y, f1(4, 5));
What is stored in x, y and z?
6
Comparison Operators
Consider the following:�
let a = 50;
let b = 50;
let result = b < a;
1. What is the VALUE of the value stored in result?
2. What is the DATA TYPE of the value stored in result?
7
Logical Operators
Consider the following:�
let c = true;
let d = true;
let result = c || d;
1. What is the VALUE of the value stored in result?
2. What is the DATA TYPE of the value stored in result?
8
Logical Operators
Consider the following:�
let a = false;
let b = true;
let c = false;
let result = !a && (b || c);
1. What is the VALUE of the value stored in result?
2. What is the DATA TYPE of the value stored in result?
9
Logical Operators
Consider the following:�
let c = true;
let d = false;
let result = c || d;
1. What is the VALUE of the value stored in result?
2. What is the DATA TYPE of the value stored in result?
10
Conditional Logic
Given the following code block, what prints to the console?
let a = true;
let b = true;
let c = false;
let result;
if (!a) {
result = 'horse';
} else if (a && c) {
result = 'donkey';
} else if (b || c) {
result = 'mule';
} else {
result = 'llama';
}
console.log(result);
11
Conditional Logic
What prints to the console?
function moveAvatar(buttonA, buttonB) {
if (buttonA && buttonB) {
console.log("jump kick");
} else if (buttonA) {
console.log("kick");
} else {
console.log("jump");
}
}
moveAvatar(true, true);
moveAvatar(true, false);
moveAvatar(false, true);
12