11CA 15 Control Structures in Java Script V02
11CA 15 Control Structures in Java Script V02
Part-I
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) Iterating
2) _______ statement can be used as alterative to if-else statement.
(a) While (b) If (c) Else-if (d) Switch
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
4) Which of the following is not a looping statement?
(a) Switch (b) While (c) Do-While (d) For
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
6) Which of the following is not a branching statement?
(a) Loop (b) If-else (c) Switch (d) For
7) What will be the output for the following snippet:
for (var n=0; n<10; n+1)
{
if (n==3)
{
break;
}
document write (n+"<br>");
}
(a) 0 1 2 (b) 0 1 2 3 (c) 0 1 2 3 4 (d) 0, 1, 3
8) In which loop the condition is evaluated, before executing a statement?
(a) While (b) Do while (c) Break (d) Continue
9) The _______ statement is especially useful when testing all the possible results of an
expression.
(a) While (b) Do while (c) Switch (d) If
10) In the _____ loop, body of the loop is always executed at least once before the condition
is evaluated
(a) For (b) While (c) If (d) Do while
11) <script type = "text / javascript">
x = 6 + "3";
document write (x);
<script> what will be the output?
Part – II
Very Short Answers
1) What are the different types of control statement used in JavaScript?
Branching or Selection statement
Looping or Repetitive statement
Part-III
Short Answers
1) What is if statement and write its types.
The “if” statement is a branching statement which transfer the control based on a condition
Types : simple “if”, “if…else”.
Simple “if”
Syntax : if(condition)
{
Statements 1 [ True block ] ;
}
When the condition returns “True”, then the statements under true block will be
executed.
When the condition returns “False”, the control will move to next statement
Eg : if(mark>=50)
alert(“pass”)
If…else
Syntax : if(condition)
{
statements 1 [True Block ];
}
else
{
statements 2 [ False block ];
}
5) 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"); }
OUTPUT :
You are eligible to get Driving Licence
Part –IV
Explain in Detail
1) Explain for loop with example
“for” loop will execute a number of times. It is an entry check loop
The syntax
for ( initialization ; condition ; increment/decrement )
{
Body of the loop;
}
<Html>
<Head>
<Title> for statement</title>
<Head>
<Body>
<script language= "javascript" type = "text/javascript")>
var no1=prompt("please enter table you want:", "0" );
document.write("<h2> multiplication for your need </h2>");
for(var no2=0; no2<=10; no2++)
{ document.write(no1+ "x" + no2+ "=" + no1*no2+ "<br>");}
</script>
</body>
</Html>
Output :
<Html>
<Head>
<Title> while</title>
<Head>
<Body>
<script language= "javascript" type = "text/javascript")>
var n=1;
while(n<=10)
{
document.write(n);
n++;
}
</script>
</body>
</Html>
Output : 1 2 3 4 5 6 7 8 9 10