1.
Name two different ways to call a function.
Correct Answer(s)
B. When it is invoked from JavaScript code
C. When an event occurs (when a user clicks a button)
Explanation
The correct answer is "When it is invoked from JavaScript code" and "When an event occurs (when a user clicks a button)". These two ways refer to different ways of calling a function in JavaScript. The first way is by directly invoking the function from JavaScript code using its name followed by parentheses. The second way is by attaching the function as an event handler to an HTML element or DOM object, so that it is called when a specific event, such as a button click, occurs.
2.
What would best describe the code below:
var nums = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
Correct Answer
B. An array of integers
Explanation
The code provided initializes a variable called "nums" with an array of integers. The array contains the numbers 1, 2, 3, 4, 5, 6, 7, 8, and 9. Therefore, the correct answer is "An array of integers."
3.
JavaScript code will load before the webpage if stored in the head tags.
Correct Answer
A. True
Explanation
When JavaScript code is placed within the head tags of an HTML document, it will load before the webpage is fully rendered. This means that any JavaScript functions or actions specified in the code will be executed before the rest of the webpage content is displayed. This can be useful for situations where the JavaScript code needs to manipulate or interact with elements on the webpage as soon as possible. Placing JavaScript in the head tags can also ensure that any necessary scripts are loaded and ready to be used before the rest of the page is loaded.
4.
It can be considered good practice to insert JavaScript code before the closing body ta, as this allows the HTML to load first
Correct Answer
A. True
Explanation
Inserting JavaScript code before the closing body tag is considered good practice because it allows the HTML to load first. By placing the JavaScript code at the end of the body, it ensures that the HTML elements have been parsed and rendered by the browser before any JavaScript code is executed. This can improve the overall performance and user experience of the website, as it allows the page content to be displayed to the user more quickly. Additionally, it can prevent any potential issues or errors that may arise if the JavaScript code tries to manipulate HTML elements that have not yet been loaded.
5.
When linking to an external JavaScript file what extension would the file have?
Correct Answer
B. .js
Explanation
When linking to an external JavaScript file, the file would have a .js extension. This is the standard file extension for JavaScript files, which allows the browser to recognize and interpret the code correctly. The .javascript, .java, and .JSCRIPT extensions are not commonly used for JavaScript files.
6.
When calling a function you pass in ......
Correct Answer
arguments
Explanation
When calling a function, you pass in arguments. Arguments are the values or variables that are passed into a function when it is called. These arguments can be used within the function to perform certain operations or calculations. By passing in arguments, you can customize the behavior of the function and make it more flexible and reusable.
7.
A user defined function or a built in function can have a list of.....
Correct Answer
B. Parameters
Explanation
A user-defined function or a built-in function can have a list of parameters. Parameters are variables that are used to pass values into a function. They allow the function to work with different values each time it is called. By specifying parameters, the function can be more flexible and reusable, as it can be used with different input values.
8.
In the loop below when i equals 2 what color will be displayed in the console?
var colours = [red, green, blue];
for(i = 0; i < colours.length; i++) {
console.log(colours[i]);
}
Correct Answer
B. Blue
Explanation
The given loop iterates over the array "colours" and prints each element to the console. Since the loop starts at index 0 and increments the value of "i" by 1 with each iteration, when "i" equals 2, the third element of the array will be printed, which is "blue".
9.
In the code below what word describes each time the loop goes round?
for(i = 0; i < 10; i++) {
console.log( i );
Correct Answer
B. Iteration
Explanation
The word that describes each time the loop goes round is "iteration". In this code, the loop is set to execute as long as the variable "i" is less than 10. Each time the loop iterates, the value of "i" is printed to the console. Therefore, "iteration" accurately describes the process of the loop going round and executing its code block repeatedly.
10.
JavaScript is commonly known as...
Correct Answer
B. Client Side Scripting Language
Explanation
JavaScript is commonly known as a client-side scripting language because it is primarily used to add interactivity and dynamic behavior to web pages on the client side, meaning it runs on the user's web browser. It allows for the manipulation of HTML elements, handling user events, and making asynchronous requests to the server. While JavaScript can also be used on the server side with platforms like Node.js, its main purpose and widespread usage is for client-side scripting.
11.
JavaScript is used to...
Correct Answer
A. Add interactivity to HTML pages
Explanation
JavaScript is used to add interactivity to HTML pages. It allows web developers to create dynamic and interactive elements on a webpage, such as form validation, image sliders, and interactive maps. By using JavaScript, users can interact with the webpage, input data, and receive responses or feedback in real-time. This makes the webpage more engaging and user-friendly. JavaScript is primarily a client-side scripting language, meaning it runs on the user's web browser rather than the server, making it an essential tool for enhancing the functionality and user experience of HTML pages.
12.
What are the variables used for?
Correct Answer(s)
A. Storing integers for manipulating in code
D. Storing Strings for manipulating in code
Explanation
Variables are used for storing different types of data in code. In this case, the variables are used for storing integers and strings for manipulation in the code. Integers can be used for mathematical calculations and storing numerical values, while strings are used for storing text or characters. These variables can be manipulated and used in various ways within the code to perform different operations or tasks.
13.
When joining 2 strings together in JavaScript this is known as?
Correct Answer
B. Concatenation
Explanation
Concatenation is the correct answer because it refers to the process of combining two or more strings together in JavaScript. It involves joining the characters or elements of one string to the end of another string, resulting in a new string that contains the combined values. This term is commonly used in programming to describe the action of merging strings.
14.
If a variable is created inside a function the variable scope would be known as...
Correct Answer
C. Local
Explanation
When a variable is created inside a function, its scope is limited to that specific function. This means that the variable can only be accessed and used within that function. This type of scope is known as "local" because it is restricted to a specific portion of the code. Local variables are useful for storing temporary or intermediate values that are only needed within a particular function. They are not accessible outside of the function, which helps to prevent naming conflicts and keeps the code organized.
15.
A Global variable can be accessed from any part of your program.
Correct Answer
A. True
Explanation
A global variable is a variable that is defined outside of any function and can be accessed from any part of the program. This means that it is not limited to a specific scope and can be used in multiple functions or modules. Therefore, the statement "A Global variable can be accessed from any part of your program" is true.
16.
Which part of the following code is the conditional statement?
if ( x > 5) {
console.log("Good Morning");
}else{"Goodnight"}
Correct Answer
B. ( x > 5)
Explanation
The conditional statement in the given code is "( x > 5)". This is the part of the code that is being evaluated to determine whether the condition is true or false. If the condition is true, the code inside the if block will be executed, which in this case is "console.log("Good Morning")". If the condition is false, the code inside the else block will be executed, which is missing in the given code but should be "console.log("Goodnight")".
17.
When Developing Software - check the boxes that would be considered good practice.
Correct Answer(s)
A. Appropriate naming of variables
B. Appropriate description/naming of functions
C. Commenting all logic in the code
Explanation
Good software development practices include appropriate naming of variables, as it improves code readability and makes it easier to understand the purpose of each variable. Appropriate description/naming of functions is also important as it helps other developers understand the functionality of each function. Commenting all logic in the code is crucial for future reference and collaboration, as it provides explanations and context for the code. However, using a cool theme is not considered a good practice in software development as it is unrelated to the functionality and quality of the software.
18.
Which one of the choices below is considered a selection construct in programming?
Correct Answer
C. If...else
Explanation
The choice "if...else" is considered a selection construct in programming because it allows the program to make decisions based on certain conditions. With the "if" statement, the program checks if a condition is true and executes a block of code if it is. If the condition is false, the program can then execute an alternative block of code using the "else" statement. This selection construct is commonly used to control the flow of the program based on different conditions.
19.
Which Animal will the if statement display in the alert box?
var animals = [ "Dog", "Cat", "Lion", "Bird", "Duck" ];
for( i = 0; i < animals.length; i++ ) {
if( i === 4) {
alert("The animal name is " + animals[ i ] );
}else{console.log(animals[ i ]); }
}
Correct Answer
D. Duck
Explanation
The if statement in the code checks if the value of i is equal to 4. When i is equal to 4, the alert box will display "The animal name is Duck". Therefore, the correct answer is Duck.
20.
Will the following condition return true OR false ?var x = 6;if( x >= 6 ) {console.log("Yes " + x + " is a Great Number")}
Correct Answer
A. True
Explanation
The condition in the given code is checking if the value of variable x is greater than or equal to 6. Since the value of x is 6, which is equal to 6, the condition will evaluate to true. Therefore, the code inside the if statement will be executed and the message "Yes 6 is a Great Number" will be printed.