0% found this document useful (0 votes)
22 views

Unit I PPT CSS 2

The document discusses client-side scripting and JavaScript. It covers different types of conditional statements in JavaScript like if, if-else, if-else-if, nested if-else, and switch-case statements. Examples are provided for each statement to explain their syntax and usage.

Uploaded by

21Siddhi Doke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Unit I PPT CSS 2

The document discusses client-side scripting and JavaScript. It covers different types of conditional statements in JavaScript like if, if-else, if-else-if, nested if-else, and switch-case statements. Examples are provided for each statement to explain their syntax and usage.

Uploaded by

21Siddhi Doke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Client Side Scripting

1
• Create interactive web pages
CO1 using program flow control
structure

• Develop JavaScript to implement


LO2 the switch-case statement for
the given problem

Department of Information Technology,Government


Polytechnic Awasari(kh)

2
TEACHING AND EXAMINATION SCHEME

Department of Information Technology,Government


Polytechnic Awasari(kh)

3
CONTENTS

1. if statement

2. if…else statement
3. if…else..if statement
4. nested if statement
5.
Switch…case statement

4
Department of Information Technology,Government
Polytechnic Awasari(kh)
IF STATEMENT
• if is a predefined keyword of JavaScript.
• It is a selection statement/decision making statement.
• If condition is true then it will execute the body of if statement.
• If condition is false then it will not execute the body of if statement.
Syntax:
if(condition)
{
//body of if
}

Example:
<html>
<body>
<script type = "text/javascript">
var age = 20;

if(age > 18)


{
document.write("Qualifies for driving");
}
</script>
</body>
</html>

5
Department of Information Technology,Government
Polytechnic Awasari(kh)
IF-ELSE STATEMENT
• if and else both are predefined keyword of JavaScript.
• It is a selection statement/decision making statement.
• If condition is true then it will execute the body of if statement.
• If condition is false then it will execute the body of else statement.
Syntax:
if(condition)
{
//body of if
}
else
{
//body of else
}

Example:
<html>
<body>
<script type = "text/javascript">

var age = 20;

if(age > 18)


{
document.write("Qualifies for driving");
}
else
{
document.write("Not Qualifies for driving");

}
</script>
</body> </html>

6
Department of Information Technology,Government
Polytechnic Awasari(kh)
IF…ELSE…IF STATEMENT
• if and else both are predefined keyword of JavaScript.
• It is a selection statement/decision making statement.
• The if...else if... statement is an advanced form of if…else that
allows JavaScript to make a correct decision out of several
conditions.
• It is a chain of if-else.

Syntax:
if(condition-1)
{
//statement-1
}
else if(condition-2)
{
//statement-2
}
else if(condition-3)
{
//statement-3
}
else
{
//statement-4
}

7
Department of Information Technology,Government
Polytechnic Awasari(kh)
IF…ELSE…IF STATEMENT- EXAMPLE
<html>
<body>
<script type = "text/javascript">

var marks = 67.78;

if(marks >= 75)


{
document.write("You got Distinction");
}
else if(marks>=60)
{
document.write("You got First Class");
}
else if(marks>=40)
{
document.write("You are Pass Only");
}
else
{
document.write("You are Fail");
}

</script>
</body>
</html>

8
Department of Information Technology,Government
Polytechnic Awasari(kh)
NESTED IF…ELSE STATEMENT
• if and else both are predefined keyword of JavaScript.
• It is a selection statement/decision making statement.
• If we use one if-else within another if-else statement then it is called as
nested if-else statement.
• This statement is used to take correct decision out of several conditions.
Syntax:
if(condition-1)
{
if(condition-2)
{
//statements
}
else
{
//statements
}
}
else
{
if(condition-3)
{
//statements
}
else
{
//statements
}

9
Department of Information Technology,Government
}
Polytechnic Awasari(kh)
NESTED IF…ELSE STATEMENT- EXAMPLE
<html>
<body>
<script type = "text/javascript">

var a=10; var b=20; var c=30;

if(a>b)
{
if(a>c)
{
document.write("Greatest Number="+a);
}
else
{
document.write("Greatest Number="+c);

}
}
else
{
if(b>c)
{
document.write("Greatest Number="+b);
}
else
{
document.write("Greatest Number="+c);

}
</script>
</body> </html>

10
Department of Information Technology,Government
Polytechnic Awasari(kh)
SWITCH CASE STATEMENT
• Switch statement is used to execute one of the statements from many
blocks of statements.
• It is a selection statement.
• There are four keywords are used i.e switch, case, break, default.
• Switch case expression value compared with case value and if it is match
then corresponding block will be executed . If none of case values are matched
then default block is executed.
Syntax:
switch(Expression)
{
case value1: //statement;
break;

case value2: //statement;


break;

case value3: //statement;


break;

default: //default statement;

Department of Information Technology,Government

11
Polytechnic Awasari(kh)
SWITCH CASE STATEMENT- EXAMPLE
<html>
<body>
<script type = "text/javascript">
var grade = 'M';
switch (grade)
{
case 'A': document.write("Good job");
break;

case 'B': document.write("Pretty good");


break;

case 'C': document.write("Passed");


break;

case 'D': document.write("Not so good");


break;

case 'F': document.write("Failed");


break;

default: document.write("Please enter valid grade");


}
</script>
</body>
</html>

12
Department of Information Technology,Government
Polytechnic Awasari(kh)
QUIZ TIME
Q1. What will be the output of the
following JavaScript code? Q2. Which statement is used to test a
specific condition?
var grade='A';
var result;
switch(grade) a) Select
{ b) If
case 'A': c) Switch
result+="10";
case 'B':
d) For
result+=" 9";
case 'C':
result+=" 8";
default:
result+=" 0";
► Ans.
} document. Write(result); ► Ans. b. If
a) 10
b) 27
c) 8
d) 0

►Ans. b. 27

13
Department of Information Technology,Government
Polytechnic Awasari(kh)
QUIZ TIME

Q3. What will be the output of  Q4.A statement block is a


the following JavaScript code?
Int a=1; a) Block that combines multiple
if(a>10) statements into a single compound
{ statement
document. Write(10);
b) Conditional block
}
else { c) Block that contains single statement
document. Write(a); d) Both conditional block and single
} statement

a) 10 ► Ans.a. Block that


b) 0 combines multiple
c) 1 statements into a single
d) Undefined compound statement

► Ans.c .1

14
Department of Information Technology,Government
Polytechnic Awasari(kh)
THANK YOU
Thank You

Department of Information Technology,Government

15
Polytechnic Awasari(kh)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy