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

Practical CSS 2-5

The document contains code examples demonstrating different JavaScript concepts including loop statements, conditional statements, arrays, functions, and string functions. Specifically, it shows a for loop to output even and odd numbers, an if/else conditional to check if a user is eligible for a driver's license, methods to manipulate an array like reverse and pop, a function to convert Celsius to Fahrenheit, and functions to convert a string to uppercase and lowercase by getting and setting the innerHTML of an element.

Uploaded by

Kunal Mhatre
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Practical CSS 2-5

The document contains code examples demonstrating different JavaScript concepts including loop statements, conditional statements, arrays, functions, and string functions. Specifically, it shows a for loop to output even and odd numbers, an if/else conditional to check if a user is eligible for a driver's license, methods to manipulate an array like reverse and pop, a function to convert Celsius to Fahrenheit, and functions to convert a string to uppercase and lowercase by getting and setting the innerHTML of an element.

Uploaded by

Kunal Mhatre
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Loop Statements

<!DOCTYPE html>

<head>

<title>Practical No_2</title>

</head>

<body>

<h3>Find Even and Odd numbers between 20</h3>

<script>

document.write("<b>Using for loop and if </b><br />");

document.write("<b>Even numbers from 1 to 20</b><br>");

for(var i=2;i<=20;i++){

if(i%2==0){

document.write("Even number is:" +i+ "<br>");

document.write("<br>");

document.write("<b>Odd numbers from 1 to 20</b><br>");

for(var i=2;i<=20;i++){

if(i%2!=0){

document.write("Odd number is:" +i+ "<br>");

</script>

</body>

</html>
Conditional Statement

<html>

<head>

<title>Practical 2</title>

</head>

<body>

<script type="text/javascript">

var age=24;

if(age>=18)

document.write("<h3>You can remove the driving licence.</h3>");

else

document.write("<h3>You cannot remove the driving licence.</h3>");

</script>

</body>

</html>
Array Program

<html>

<head>

<title>Arrays!!!</title>

<script type="text/javascript">

var languages = new Array("C", "C++", "HTML", "Java", "VB");

Array.prototype.displayItems=function(){

for (i=0;i<this.length;i++){

document.write(this[i] + "<br />");

document.write("Programming lanugages array<br />");

languages.displayItems();

document.write("<br />The number of items in languages array is " + languages.length + "<br />");

document.write("<br />The REVERSED languages array<br />");

languages.reverse();

languages.displayItems();

document.write("<br />The languages array after REMOVING the LAST item<br />");

languages.pop();

languages.displayItems();

document.write("<br />THE languages array after PUSH<br />");

languages.push("JavaScript");

languages.displayItems();

document.write("<br />The languages array after SHIFT<br />");

languages.shift();

languages.displayItems();

</script>
</head>

<body>

</body>

</html>
Functions Program

<html>

<head>

<script>

function toFahrenheit(celsius) {

return (celsius * 9/5 + 32);

document.write("Temperature in Fahrenheit is " + toFahrenheit(45));

</script>

</head>

<body>

</body>

</html>
String Function

<html>

<head>

<script>

function toUpper() {

var text = document.getElementById('panel').innerHTML

document.getElementById('panel').innerHTML = text.toUpperCase()

function toLower() {

var text = document.getElementById('panel').innerHTML

document.getElementById('panel').innerHTML = text.toLowerCase()

</script>

</head>

<body>

<p id="panel">Click on buttons to change case.</p>

<input type="button" value="UPPERCASE" onclick="toUpper()" />

<input type="button" value="lowercase" onclick="toLower()" />

</body>

</html>

You might also like