0% found this document useful (0 votes)
32 views2 pages

Class 12 JavaScript Test

The document contains a series of JavaScript output questions aimed at Class 12 students. It includes predicting outputs of functions, calculating sums in loops, identifying errors in code, and converting structures like if-else and for loops into switch-case and while loops. Each question is presented with multiple-choice options or requires code transformation.

Uploaded by

sakshijha1014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Class 12 JavaScript Test

The document contains a series of JavaScript output questions aimed at Class 12 students. It includes predicting outputs of functions, calculating sums in loops, identifying errors in code, and converting structures like if-else and for loops into switch-case and while loops. Each question is presented with multiple-choice options or requires code transformation.

Uploaded by

sakshijha1014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Class 12 JavaScript Output Questions

1. Predict the output of the following JavaScript code:

function calculate(num) {
if (num <= 1) return num;
return calculate(num - 1) + calculate(num - 2);
}

console.log(calculate(5));

(a) 8 (b) 5 (c) 13 (d) 15

2. What will be the output of the following code?

let sum = 0;
for (let i = 1; i <= 5; i++) {
if (i % 2 === 0) {
sum += i * 2;
} else {
sum += i;
}
}
console.log(sum);

(a) 15 (b) 20 (c) 25 (d) 30

3. Identify the error in the following JavaScript code:

let num = 5;
for (num < 10; num++) {
console.log(num);
}

(a) Incorrect loop condition


(b) Incorrect use of for loop syntax
(c) Missing braces
(d) No error
4. Convert the following if-else structure into a switch-case:

let grade = "B";

if (grade === "A") {


console.log("Excellent");
} else if (grade === "B") {
console.log("Good");
} else if (grade === "C") {
console.log("Average");
} else {
console.log("Fail");
}

5. Convert the following for loop into a while loop:

for (let i = 1; i <= 5; i++) {


console.log(i * i);
}

You might also like