1/40
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which of the following is not a valid value for a boolean?
yes
What symbol represents the and operator in JavaScript?
&&
What symbol represents the or operator in JavaScript?
||
After the following code runs, what is the value of isWeekend?
var isSaturday = true;
var isSunday = false;
var isWeekend = isSaturday || isSunday;
true
What is the proper way to compare if two values are equal in a boolean expression in JavaScript?
==
What is the proper operator for "not equals" in JavaScript?
!=
How can we check if a variable num is even?
(num % 2 == 0) will be true
What kind of statement allows us to run a block code only if a certain condition is true?
if statement
What kind of statement allows us to run one block of code if one condition is true, and a separate block of code otherwise?
if/else statement
How many times will the following program print "hello"?
for (var i = 0; i < 5; i++) {
println("hello");
}
5
In the following code, what will be the last number to print to the screen before the program finishes?
for (var i = 0; i < 10; i++) {
if (i % 2 == 0) {
println(i);
} else {
println(2 * i);
}
}
18
How many times will the following code print "hello"?
for (var i = 3; i < 8; i++) {
println("hello");
}
5 **YES AGAIN
How many times will the following code print "hello"?
for (var i = 0; i < 8; i += 2) {
println("hello");
}
4
Why do we use constant variables?
All of the Above
Which of the following is a good example of a proper constant variable name?
var MAX_VALUE = 100;
What will be the value of sum after this code runs?
var START = 1;
var END = 4;
function start(){
var sum = 0;
for(var i = START; i <= END; i++){
sum += i;
}
}
10
Which of the following returns a random number between 1 and 10?
Randomizer.nextInt(1, 10)
How many possible values can Randomizer.nextBoolean() return?
2
How many times will this program print "hello"?
var i = 10;
while (i > 0) {
println("hello");
i--;
}
10
How many times will this program print "hello"?
var i = 50;
while (i < 100) {
println("hello");
}
This code will loop infinitely
What statement can we use inside of a loop to end it?
break
What is the term for the value that signals the end of user input?
sentinel
Which of the following is correct loop and a half structure?
while(true){
//code
if(condition){
break;
}
//code
}
4.10.5: Better Password Prompt
var SECRET = "abc123";
function start(){
while (true)
var password = ("What is the password? ");
if (password == "abc123") {
break;
}
}
}
Boolean
true or false value.
Logical Operator
Used to make logical associations between boolean values
OR Operator
Logical operator that ___ two boolean values. Written as ||. a || b will be true if a or b is true.
Not Operator
Logical operator that negates a single boolean value. Written as !. !a will be true if a is false, and false if a is true.
And Operator
Logical operator that ___ two boolean values. Written as &&. a && b will be true if both a and b are true.
Comparison Operator
Used to make comparisons between values.
If Statement
lets you ask a question to the program and only run code if the answer is true.
If-Else
Control structure that lets us run either one section of code or another depending on a test.
Event
an action (such as clicking the mouse or pressing a key on the keyboard) that a program detects and uses as input.
For Loop
lets us repeat code a fixed number of times.
Randomize
To generate or select a random object
Psuedorandom
Not actually random, but appears to be random
While Loop
Lets us repeat code as long as something is true
Infinite Loop
A loop that has no eay of stopping, and will keep looping forever
Sentinel
A constant that has the specific purpose of being the value that breaks out of a loop
Break Statement
Statement that breaks out of the current loop, without executing any more code in the loop
Loop-and-a-half
most often set with a while(true), that has a break statement in the loop body.