1/39
Flashcards based on JavaScript quiz questions and answers.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which of the following is a valid for loop in JavaScript?
for (var i = 0; i < 5; i++) { console.log(i); }
What is an example of a keyboard event in JavaScript?
keydown
What does the following code do? keyDownMethod(keyFunction); function keyFunction(event) { console
It logs the key pressed on the keyboard
How many value pairs are logged by this loop? for (var i = 0; i < 3; i++) { for (var j = 0; j < 2; j++) { consol
6
What does the && operator represent?
Logical AND
What is the purpose of nested for loops?
To perform repetitive tasks in a grid-like structure
What is a boolean value?
A value that is either true or false
How can you make a for loop count backwards from 10 to 0?
for (var i = 10; i >= 0; i--)
How would you fix this infinite loop? var counter = 0; while (counter < 5) { console.log(counter); }
Add counter++; inside the loop
What does this code print? for (int i = 0; i < 10; i++) { console.log(Randomizer.nextInt(1, 2)); }
It prints either 1 or 2 randomly each of ten times
What's the bug in this code? var count = 0; while (count < 5) { console.log(count); }
The loop will run infinitely
Why are random numbers useful in programming?
They help simulate unpredictable real-world events
What's the bug in this loop-and-a-half structure? while (true) { var input = readLine("Enter a number:");
readLine() doesn't return a number
Which scenario is a good use of a loop-and-a-half?
Searching through a list until a specific item is found
Which statement about infinite loops is true?
They can cause the program to freeze or crash
What does this do-while loop output if number is initially 5?
5
What is the output of addNumbers(5, 10)?
15
What is the output of this code? multiply(2, 5);
10
What does double(3) return?
6
What will isEven(4) return?
true
How many parameters can a function take?
As many as you want
Why use a function with parameters rather than fixed values?
To allow flexibility and reuse of the function with different inputs
What happens if you define parameters but call the function without arguments?
The parameters will be undefined
Which is a function with multiple parameters?
function calculateArea(width, height) { return width * height; }
How do local variables help organize code?
They prevent naming conflicts between different parts of the program
What is a local variable?
A variable that is declared within a function and only accessible within that function
What does this code output? var globalVar = "I am a variable."; function testScope() { console.log(globa
"I am a variable."
Why are APIs important for developers?
They allow for code reuse and simplify complex operations
Which variable should be declared globally?
A constant value used throughout the program
What is an API (Application Programming Interface)?
A set of functions and tools that allow different software components to communicate
How is Karel's move() an example of an API?
It abstracts complex movement logic into a simple function call
What will this code output? var count = 0; function increment() { var myLocal = count; count++; } increm
1
Which task would require traversing a list?
Finding out how many even numbers there are in the list
What is the length property of an array used for?
To determine the number of elements in the array
What will this code print? var arr = [1, 2, 3, 4]; arr[1] = arr[3] - arr[1]; println(arr);
[1, 2, 3, 4]
"Dali" is located at which index in this list: ["Ada", "Bao", "Cedric", "Dali", "Elena"]
3
What should replace
i < list.length
What is the value of index in this code?
1
How to remove the last item in an array and store it?
var lastTask = tasks.pop();
Which element is at index 1 in ["carrots", "peas", "sprouts", "okra"]?
"peas"