Question 40
Answer: A. str == ""
Explanation: To check if a string is empty, compare it to an empty string "".
Question 39
Answer: B. window
Explanation: The window object is used to display popup windows
like alert(), confirm(), or prompt().
Question 38
Answer:
• sampleStudent = "HTML Student"
• [Link] = "JavaScript"
• [Link] = 100
Explanation: Primitive types (like sampleStudent) are passed by value, while
objects (like sampleCourse) are passed by reference.
Question 37
Answer:
• Page load: Add changeColor(); inside a [Link] or <body
onload="changeColor()">.
• Button click: Use onclick="changeColor()" on the button.
Note: The provided changeColor() function has syntax errors
(e.g., win, Man, table are undefined).
Question 36
Answer:
javascript
Copy
function safeRoot(a, b) {
if (a >= 0) return [Link](a, 1 / b);
else if (b % 2 === 0) return "Result is an imaginary number";
else return -[Link](-a, 1 / b);
Explanation: The function must handle non-negative a, even/odd b for negative a.
Question 35
Answer: B. onmouseenter, D. onmouseover
Explanation: These events trigger when the mouse enters/hovers over the
image. onmouseout would revert the image.
Question 34
Answer:
• [Link](y) → Error (const y cannot be reassigned).
• [Link](3 * x) → 54 (from catch).
• [Link](4 * x) → 72 (from finally).
Final Output: 54, 72.
Question 33
Answer:
javascript
Copy
var numbers = [];
for (var i = 0; i < 10; i++) {
[Link]([Link]([Link]([Link]() * 10)));
var sum = 0;
for (var j = 0; j < 10; j = j + 2) {
sum += numbers[j];
}
[Link](sum);
Explanation: Fill array with random numbers, then sum every other element.
Question 32
Answer: D. [Link]("tester").innerHTML = randomQuote();
Explanation: innerHTML updates the content of an element.
Question 31
Answer: C. In a .js file
Explanation: External JavaScript files promote reusability and maintainability.
Question 30
Answer:
javascript
Copy
function validGraphic(height, width) {
if (height >= 50 && height < 100) {
valid = true;
Explanation: The function checks if height is between 50 and 100.
Question 29
Answer:
• n = 10
• c = 55
• a=0
• d=5
Explanation:
• c = 50 + 5 = 55
• a = 50 % 2 = 0
• d = 55 / 11 = 5
• n = 5 * 2 = 10.
Question 28
Answer: D. noscript
Explanation: The <noscript> tag displays content when JavaScript is disabled.
Question 27
Answer:
• "ABCD" → False
• 1234 → True
• 28 * 59 → False
Explanation: The function checks if pin is a 4-digit number (implicitly numeric).
Question 25
Answer:
• var age = 23; → Number
• var except = false; → Boolean
• var initial = '0'; → String
• var salary = 123.5; → Number
• var zip = "E1086"; → String
Question 24
Answer:
javascript
Copy
if ([Link]() - [Link]() <= 3) {
[Link]("Customer " + [Link] + " placed order " +
dateDiff(currentDate, orderDate));
Explanation: Checks if the order date is within the last 3 years.
Question 23
Answer: A. [Link]("para").innerHTML += room[i];
Explanation: Appends each room type to the paragraph.
Question 22
Answer:
javascript
Copy
function showArea(length, width) {
alert(length * width);
Explanation: The correct standalone function for an external .js file.
Question 21
Answer:
javascript
Copy
if (day === "wednesday") discount = 0.1;
else discount = 0;
Explanation: Applies a 10% discount only on Wednesday.
Question 20
Answer: B. 1010
Explanation: String concatenation occurs ("16" + "10" = "1610").
Question 19
Answer:
javascript
Copy
function calculate(operation, a, b) {
switch (operation) {
case 'multiply': return a * b;
case 'divide': return a / b;
Explanation: The function routes operations to the correct calculation.
Question 18
Answer:
javascript
Copy
for (i = 0; i < [Link]; i++) {
if (list[i] == null) continue;
if (list[i] == 'orange') {
alert('found');
break;
Explanation: continue skips null, break exits the loop when orange is found.
Question 17
Answer:
• Form POST requests are cached. → False
• GET requests have restricted data length. → True
• POST requests are stored in browser history. → False
• Use GET for sensitive data. → False
Question 16
Answer:
• ceil = 101
• floor = 100
• round = 101
Question 15
Answer:
javascript
Copy
[Link]("title").innerHTML = "Wish List";
[Link]("showList").innerHTML = text;
Explanation: Updates the title and list dynamically.
Question 13
Answer:
javascript
Copy
for (let i = start; i >= 0; i--) {
[Link](i);
}
Explanation: Counts down from start to 0.
Question 12
Answer: B. getElementById
Explanation: Accesses the element with id="section1".
Question 11
Answer:
javascript
Copy
function showList() {
var list = [Link]("li");
for (var i = 0; i < [Link]; i++) {
[Link]("list").innerHTML += list[i].textContent + "<br>";
Explanation: Collects all <li> elements and displays their text.
Question 10
Answer: A. An exception is thrown and caught.
Explanation: const sum cannot be reassigned, causing an error.
Question 9
Answer:
javascript
Copy
if (age >= 24 && age < 36) category = 'CAT2';
else if (age >= 36 && age < 46) category = 'CAT2';
else category = 'CAT3';
Explanation: Assigns categories based on age ranges.
Question 8
Answer:
javascript
Copy
function ticketPrice(age) {
if (age < 5 || age >= 65) return 0;
else if (age >= 5 && age <= 17) return 10;
else return 20;
Explanation: Implements the pricing rules.
Question 7
Answer: A.
javascript
Copy
[Link] = [Link];
[Link] = true;
Explanation: Updates the paragraph and hides the input box.
Question 6
Answer: The form will not submit because it is missing the submission method.
Explanation: The button lacks type="submit" or form event handling.
Question 5
Answer:
javascript
Copy
var newImgElement = [Link]("img");
[Link] = "_images/[Link]";
[Link](newImgElement);
Explanation: Creates and inserts an image at the start of the body.
Question 4
Answer: C. Change line 10 to var option =
[Link]["heatIndex"].value;
Explanation: Accesses the selected value correctly.
Question 3
Answer:
javascript
Copy
function Student(first, last, major, year) {
[Link] = first;
[Link] = last;
[Link] = major;
[Link] = year;
[Link] = function() {
[Link]("<p>You are registered as " + [Link] + " " + [Link] +
"</p>" + "<p>You are a " + [Link] + " majoring in " + [Link] + "</p>");
};
Explanation: Constructor function for student registration.
Question 2
Answer: [100, 40, 60, 10]
Explanation:
• shift() removes 20 → [40, 60, 80]
• pop() removes 80 → [40, 60]
• push(10) → [40, 60, 10]
• unshift(100) → [100, 40, 60, 10].
Question 1
Answer: D. 75
Explanation: x *= 5 is equivalent to x = x * 5 → 15 * 5 = 75.