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

2nd CSS1

The document contains code snippets demonstrating different JavaScript conditional and looping statements, including if/else statements, nested if statements, switch statements, for loops, while loops, and do/while loops. It was submitted as a student assignment containing name, roll number, practical number, code examples, and expected output for each statement or loop covered.

Uploaded by

Ganesh Ekambe
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)
14 views

2nd CSS1

The document contains code snippets demonstrating different JavaScript conditional and looping statements, including if/else statements, nested if statements, switch statements, for loops, while loops, and do/while loops. It was submitted as a student assignment containing name, roll number, practical number, code examples, and expected output for each statement or loop covered.

Uploaded by

Ganesh Ekambe
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/ 12

Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02
Code:
1. If statement

<html>
<input type="button" value="click me" onclick="disp()">
<script type="text/javascript">
function disp()
{
a=18;
b=15;
if(a>b)
{
alert("a is Greater ");
}
}
</script>
</html>

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02
2. If else Statement

<!DOCTYPE html>
<html>
<head>
<title>Leap Year Checker</title>
</head>
<body>
<h1>Leap Year Checker</h1>
<p>Enter a year to check if it's a leap year:</p>
<input type="text" id="yearInput" placeholder="Enter a year">
<button onclick="checkLeapYear()">Check</button>
<p id="result"></p>

<script>
function checkLeapYear() {
var input = document.getElementById("yearInput").value;
var year = parseInt(input);

if (isNaN(year)) {
document.getElementById("result").textContent = "Please
enter a valid numerical year.";
return;
}

if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0)


{
document.getElementById("result").textContent = year + " is a
leap year!";
} else {
document.getElementById("result").textContent = year + " is
not a leap year.";
}
}
</script>
</body>
</html>
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02

If Else

<html>
<input type="button" value="click me" onclick="disp()">
<script type="text/javascript">;
function disp()
{
var i= 7;
if(i<10)
{
alert("7 is less than 10");
}
Else
alert("7 is not less than 10");
}
</script>
</html>

*output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02

3. Nested if Statement

<html>
<input type="button" value="click me" onclick="disp()">
<script type="text/javascript">
function disp()
{
var age = 15;

if( age < 18 )


{
alert(" You are Minor. ");

}
else
{
if (age >= 18 && age <= 60 )
{
alert(" You are Eligible to Work. ");

}
else
{
alert(" You are too old to work as per the Government rules ");

}
}
}
</script>

</html>

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02
Switch case

<!DOCTYPE html>
<html>
<body>
<label for="dayNumber">Enter a day number (1-7):</label>
<input type="number" id="dayNumber">
<button onclick="getDayOfWeek()">Get Day of the Week</button>
<p id="output"></p>
<script>
function getDayOfWeek() {
const dayNumber =
parseInt(document.getElementById("dayNumber").value);
let dayName = "";

switch (dayNumber) {
case 1:
dayName = "Sunday";
break;
case 2:
dayName = "Monday";
break;
case 3:
dayName = "Tuesday";
break;
case 4:
dayName = "Wednesday";
break;
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02
case 5:
dayName = "Thursday";
break;
case 6:
dayName = "Friday";
break;
case 7:
dayName = "Saturday";
break;
default:
dayName = "Invalid day number";
break;
}

document.getElementById("output").textContent = "Day of the week: " +


dayName;
}
</script>
</body>
</html>

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02

• LOOPING STATEMENT
• For

<!DOCTYPE html>
<html>
<body>
<h1>Alphabet</h1>
<p id="alphabet"></p>
<script>
var alphabet = "";
for (var i = 97; i <= 122; i++) {
var letter = String.fromCharCode(i);
alphabet += letter;
}

var outputElement = document.getElementById("alphabet");


outputElement.textContent = "Alphabet: " + alphabet;
</script>
</body>
</html>

OUTPUT
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02
WHILE LOOP

<!DOCTYPE html>
<html>
<head>
<title>Odd Number Finder</title>
</head>
<body>
<h1>Odd Numbers from 1 to 20</h1>

<p>Odd numbers:</p>
<ul id="output"></ul>

<script type ="text/Javascript">


let num = 1;
while (num <= 20) {
if (num % 2 !== 0) {
const listItem = document.createElement("li");
listItem.textContent = num;
document.getElementById("output").appendChild(listItem);
}
num++;
}
</script>
</body>
</html>

Output

Do while loop

<!DOCTYPE html>
<html>
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02

Do while loop

<head>
<title>Vowel Finder</title>
</head>
<body>
<label for="inputString">Enter a string:</label>
<input type="text" id="inputString">
<button onclick="findVowels()">Find Vowels</button>
<p id="output"></p>

<script>
function findVowels() {
const inputString = document.getElementById("inputString").value;
const vowels = "aeiouAEIOU";
let foundVowels = "";

let index = 0;
do {
if (vowels.includes(inputString[index])) {
foundVowels += inputString[index] + " ";
}
index++;
} while (index < inputString.length);

if (foundVowels === "") {


document.getElementById("output").textContent = "No vowels found.";
} else {
document.getElementById("output").textContent = "Vowels found: " +
foundVowels;
}
}
</script>
</body>
</html>
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 02

Output

You might also like