[go: up one dir, main page]

0% found this document useful (0 votes)
9 views5 pages

Textbook Exercise-G6 - M5

The document contains answers to textbook exercises related to JavaScript, including fill-in-the-blanks, true/false statements, matching questions, multiple-choice questions, and short answer sections. It covers concepts such as conditional statements, loops, break and continue keywords, and the use of if...else structures. Additionally, it provides examples and explanations of various programming constructs in JavaScript.

Uploaded by

binianand85
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)
9 views5 pages

Textbook Exercise-G6 - M5

The document contains answers to textbook exercises related to JavaScript, including fill-in-the-blanks, true/false statements, matching questions, multiple-choice questions, and short answer sections. It covers concepts such as conditional statements, loops, break and continue keywords, and the use of if...else structures. Additionally, it provides examples and explanations of various programming constructs in JavaScript.

Uploaded by

binianand85
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/ 5

Answers of textbook exercises

Fill in the Blanks

1.​ If num=10, value of num>10 is false


2.​ Conditional statement is used in Javascript for
decision making.

3.​ Output of comparison comparison operator is always


true/false.

4.​ The break keyword can stop the loop before it has looped
through all the items.

5.​ The continue keyword can skip the remaining part of the
code and pass control to the beginning of the loop.

State True or False

1.​ We can use optional else block with while and for loops in
JavaScript. - True
2.​ continue statement passes control to the beginning of the loop. -
True
3.​ A computer can make decisions by itself. - False
4.​ The code inside the if block is executed when the test expression
evaluates to true. - True
5.​ ‘for loop’ can’t be used for iterating through the elements of a
sequence.- False
Match the Following

1.​ Loop c. Repeating a task

2.​ Break a. Exit loop

3.​ 25 > 22 e. True

4.​ !true b. false

5.​ else d. Executes when the condition is


False

Multiple choice questions

1.​ else block is executed when the condition is:


a.​ True
b.​ False
c.​ Never
d.​ None of the above

2.​ What is the term for one execution of a loop?


a.​ Counter
b.​ Function
c.​ Run
d.​ Iteration

3.​ What is the output of the following code?


n=0
while (n < 4){
n = n + 1;
}
document.write(“Value of n is” + n);
a.​ Value of n is 2
b.​ Value of n is 3
c.​ Value of n is 4
d.​ Value of n is 5

4.​ For checking multiple conditions we use:


a.​ if block only
b.​ if... else
c.​ if ... else if ... else
d.​ None of the above

5.​ In JavaScript, operator for logical and operation is:


a.​ ||
b.​ &&
c.​ !
d.​ #

Answer in one word or one sentence

1.​ What is the use of a break statement in JavaScript?


It is used to terminate a loop prematurely in JavaScript.

2.​ Write a code to execute an infinite loop in JavaScript.


while(true) { // Code here }

3.​ What is strict equal(===) in JavaScript?


It checks both the value and the type for equality.

4.​ What is an assignment operator?


Assigns a value to a variable. For example, `=` in JavaScript.

5.​ Output of a test expression given inside an if statement will be:


determined by whether the test expression evaluates to true or
false.
Answer the following

1.​ Write down the syntax of Javascript if... else if ladder with an
example.
if (condition1) {
// Code block executed if condition1 is true
} else if (condition2) {
// Code block executed if condition2 is true
} else {
// Code block executed if none of the conditions are true
}
Example:
let num = 10;
if (num > 10) {
console.log("Number is greater than 10");
} else if (num < 10) {
console.log("Number is less than 10");
} else {
console.log("Number is equal to 10");
}

2.​ What is the difference between ‘nested if’ and if... else if ladder?
The difference between nested if and if...else if ladder is that
nested if statements are multiple if statements within another if
statement, creating a branching structure, whereas if...else if ladder
is a series of if statements followed by optional else if blocks,
where each condition is checked sequentially until one is true,
providing a linear decision-making process.
3.​ Write a program to input a number, and find out whether it is
greater than or less than 100.
let num = parseInt(prompt("Enter a number:"));
if (num > 100) {
console.log("Number is greater than 100");
} else if (num < 100) {
console.log("Number is less than 100");
} else {
console.log("Number is equal to 100");
}

4.​ What is the use of Loop in programming. What are the loops
available in JavaScript?
Loops in programming are used to repeat a block of code multiple
times. In JavaScript, common types of loops include the for loop,
while loop, and do...while loop. They allow efficient execution of
repetitive tasks, iterating over arrays or sequences, and
implementing conditional logic.

5.​ What are loop control statements in JavaScript?


Loop control statements in JavaScript include break, continue, and
labeled statements. Break is used to exit a loop prematurely,
continue skips the current iteration and moves to the next, while
labeled statements provide a way to break or continue nested loops
based on specific conditions.

You might also like