Control Structure in Javascript: book back answers

18 solved questions from the end of this chapter, Class 11 Computer Applications, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.

← Notes and quiz for Control Structure in Javascript

Choose the correct answers

  1. Which conditional statement is used to transfer control from current statement to another statement?

    • (a) Branching
    • (b) Sequencing
    • (c) Looping
    • (d) Interating
    Try it, then show the answer

    (a) Branching

    Branching transfers control from the current statement to another statement or construct.

    From the book: “Branching is a transfer of control from the current statement to another statement”

  2. _______ statement can be used as alterative to if-else statement.

    • (a) While
    • (b) If
    • (c) Else-if
    • (d) Switch
    Try it, then show the answer

    (d) Switch

    The chapter describes switch as an alternative to using an if...else structure.

    From the book: “JavaScripts offers the switch statement as an alternate to using if...else structure.”

  3. Which statement in switch case is used to exit the statement once the appropriate choice is found?

    • (a) Exit
    • (b) Default
    • (c) Case
    • (d) Break
    Try it, then show the answer

    (d) Break

    The break statement exits the switch once the appropriate choice is found.

    From the book: “The break statement is also used commonly within switch to exit the statement once the appropriate choice is found.”

  4. Which of the following is not a looping statement?

    • (a) Switch
    • (b) While
    • (c) Do-While
    • (d) For
    Try it, then show the answer

    (a) Switch

    The chapter lists for, while, and do..while as looping statements; switch is a branching statement.

    From the book: “JavaScript supports three kinds of looping statements. They are • for loop • while loop • do..while loop”

  5. Which part of the loop statement determines the number of times, the loop will be iterated? (MOT)

    • (a) First
    • (b) Second
    • (c) Third
    • (d) Final
    Try it, then show the answer

    (b) Second

    The second part is the conditional statement that determines how many times the loop is iterated.

    From the book: “The second part is the conditional statement that determines how many times the loop will be iterated.”

  6. In which loop the condition is evaluated, before executing a statement? (MOT)

    • (a) While
    • (b) Do while
    • (c) Break
    • (d) Continue
    Try it, then show the answer

    (a) While

    A while loop evaluates its condition before executing the loop statement.

    From the book: “The condition is evaluated before executing the statement.”

  7. The _______ statement is especially useful when testing all the possible results of an expression. (LOT)

    • (a) While
    • (b) Do while
    • (c) Switch
    • (d) If
    Try it, then show the answer

    (c) Switch

    The switch statement is useful for testing the possible results of an expression.

    From the book: “The switch statement is especially useful when testing all the possible results of an expression.”

Very Short Answers

  1. What are the different types of control statement used in JavaScript?

    Try it, then show the answer

    Branching / Selection and Looping / repetitive.

    The chapter divides control types into branching/selection and looping/repetitive controls.

    From the book: “There are two types of controls, • Branching / Selection • Looping / repetitive”

  2. What is meant by conditional statements in JavaScript?

    Try it, then show the answer

    Conditional statements execute or skip one or more statements depending on the value of a specified conditional expression.

    They determine whether statements are executed or skipped based on the conditional expression's value.

    From the book: “Conditional statements execute or skip one or set of statements depending on the value of a specified conditional expression.”

  3. List out the various branching statements in JavaScript?

    Try it, then show the answer

    if statement, if … else statement, else if statement, and switch statement.

    These are the branching statements listed in the chapter.

    From the book: “• if statement • if … else statement • else if statement • switch statement”

  4. Write the general syntax for switch statement

    Try it, then show the answer

    switch(expression) { case label1: statements1; break; case label2: statements2; break; case labeln: statements - N; break; default: statements; }

    The switch expression is matched against case labels; default provides a path when no case matches.

    From the book: “The syntax of a switch structure as the following: switch(expression)”

  5. Differentiate the break and continue statement.

    Try it, then show the answer

    break terminates the loop early; continue ends the current iteration and starts the next iteration.

    Break exits the loop, whereas continue skips the remaining work of the current iteration and proceeds to the next one.

    From the book: “The break statement will terminate the loop early.”

Short Answers

  1. What is if statement and write its types.

    Try it, then show the answer

    The if statement allows JavaScript to execute statements conditionally. Its two forms are if and if...else.

    The first form executes a true block when the condition is true. The second provides an alternate path when the condition is false.

    From the book: “The if statement is the fundamental control statement that allows JavaScript to make decisions to execute statements conditionally.”

  2. What is called a loop and what are its types?

    Try it, then show the answer

    A loop repeatedly executes the same portion of code, possibly with slightly different values. The types are for, while, and do..while.

    The chapter describes loops as repeated execution and names three supported looping statements.

    From the book: “the same portion of code needs to be executed many times with slightly different values is called Loops.”

  3. Differentiate between while and do while statements

    Try it, then show the answer

    In a while loop, the condition is tested before the body, so the body may not execute. In a do..while loop, the condition is tested after the body, so the body executes at least once.

    The difference is when the condition is tested: at the start for while and at the end for do..while.

    From the book: “the loop expression is tested at the end of the loop rather than at the beginning.”

  4. What message will be displayed, if the input for age is given as 20, for the following snippet. if (age> = 18 ) alert ("you are eligible to get Driving licence"} } else alert ("you are not eligible to get driving licence"); }

    Try it, then show the answer

    you are eligible to get Driving licence

    With age 20, the condition age >= 18 is true, so the if branch displays its message.

    From the book: “if(age>=18) { alert("You Are Eligible to get Driving Licence.."); }”

Part –IV Explain in Detail

  1. Explain switch case statement with example

    Try it, then show the answer

    The switch statement is an alternative to using an if...else structure. It is useful when testing all the possible results of an expression.

    1. Evaluate the expression: The switch statement evaluates the expression placed between parentheses.
    2. Compare case labels: The result is compared with the labels associated with the case structures. When a label matches, its corresponding statements are executed.
    3. Use break: The break statement is commonly used to exit the switch after the appropriate choice is found.
    4. Use default: The default structure is used when the expression result does not match any case label.
    5. Example: assign a grade: In the chapter example, marks are used to assign a grade value. The switch then displays the corresponding grade message; unmatched values use the default message.

    Example: The chapter assigns grade values from the marks and uses switch(grade) to display messages such as “Your Grade is Outstanding..” and “Your Grade is Excellent..”.

    Thus, switch selects and executes the statements for the matching case, with default providing an alternative when no case matches.

    From the book: “If the result is equal to a label, the statements in the corresponding case structure are executed.”

  2. Write a Java Script program using while statement to display 10 numbers.

    Try it, then show the answer

    A while loop repeatedly executes a statement or block of statements as long as its condition is true. The condition is checked before each execution of the loop body.

    1. Program: The following JavaScript program uses a counter to display ten numbers, from 1 to 10.
    2. Initialise the counter: Set the counter variable to 1 before the loop begins.
    3. Set the condition: The condition no2 <= 10 allows the loop to run for ten iterations.
    4. Display and increment: Display the counter value, then increase it by 1 so the loop progresses.

    Example: The chapter’s while-loop illustration displays values using document.write(no2+" "); and increments the counter with no2=no2+1;.

    Thus, the while statement displays ten numbers by repeating the loop until its condition becomes false.

    From the book: “The while statement creates a loop that executes a specified statement as long as the test condition evaluates to true.”

Next chapterJavaScript Functions