1(a).
Develop a javascript program to capitalize the first letter of each
word of a sentence(string).
<!DOCTYPE html>
<html>
<head>
<title> CAPITAL LETTERS</title>
</head>
<body>
<script>
const cap=function(sentence)
{
let str= [Link](" ");
for(let i=0;i<[Link];i++)
{
str[i]=str[i][0].toUpperCase()+str[i].substring(1);
}
return [Link](" ");
}
[Link](cap("javascript and jquery interactive front end web
development"));
[Link]("<br>");
[Link](cap("i love my india"));
</script>
</body>
</html>
OUTPUT:
1(b) Develop a javascript program to check a string starts with ‘java’.
<!DOCTYPE html>
<html>
<body>
<script>
function start(str)
{
[Link](str+"-->");
if([Link]<4)
{
return false;
}
front=[Link](0,4);
if(front=='java')
{
return true;
}
else
{
return false;
}
}
[Link](start("javascript"));
[Link]("<br>");
[Link](start("java"));
[Link]("<br>");
[Link](start("python"));
[Link]("<br>");
[Link](start("c++"));
</script>
</body>
</html>
OUTPUT:
2(a) develop a javascript program to display the current day and a time.
<!DOCTYPE html>
<html>
<head>
<title>
print current day and time
</title>
</head>
<body>
<script type="text/javascript">
var myDate = new Date();
var myDay = [Link]();
// Array of days.
var weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'];
[Link]("Today is : " + weekday[myDay]);
[Link]("<br/>");
// get hour value.
var hours = [Link]();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
var minutes = [Link]();
minutes = minutes < 10 ? '0' + minutes : minutes;
var myTime = hours + " " + ampm + " : " + minutes +
" : " + [Link]();
[Link]("\tCurrent time is : " + myTime);
</script>
</body>
</html>
OUTPUT:
2(b) develop a javascript program to reverse a given string
<!DOCTYPE html>
<html>
<head>
<title>Reverse a String</title>
<script>
[Link]=function(){
return [Link]("").reverse().join("");
}
</script>
</head>
<body>
<p>
<label for="s">ENTER A STRING</label>
<input type = "text" id = "s" size = "40">
</p>
<p id = "t"></p>
<input type = "button" id = "r" value = "Reverse"
onclick="[Link]
('t').innerHTML = [Link]('s').[Link]();">
</body>
</html>
OUTPUT:
3(a). Write a Javascript program to display a message using alert.
<html>
<head>
<style>
body { background-color:lightgreen;}
p {color:brown;}
</style>
<script type = "text/javascript">
function fun()
{
alert ("WELCOME!!! This is KSIT, CSD Department");
}
</script>
</head>
<body style="text-align:center"> <h1>
<p> Click the following button to see the effect </p>
</h1>
<form>
<button onclick="fun()"><h2>CLICK ME</h2></button>
</form>
</body>
</html>
OUTPUT:
3(b). write a javascript program to display a confirm message on a button
click
<!DOCTYPE html>
<html>
<head>
</head>
<body style="text-align:center">
<h1> Click the button to invoke the Confirm Message</h1>
<button onclick="myFunction()"><h2>CLICK HERE</h2></button>
<h2><p id="conf" ></p> </h2>
<script>
function myFunction() {
if ([Link]("Do you really want to delete?\n Deletion can not be reverted if you confirm!")) {
[Link]("conf").innerHTML = "you have successfully deleted the file"
}
}
</script>
<style>
body { background-color:powderblue;}
p {color:green;}
h1{color:purple;}
</style>
</body>
</html>
OUTPUT:
3(c). write a javascript program to read value through prompt window and
display the value on a button click.
<html>
<h1> PROMPT MESSAGE </h1> <br> <br>
<body style="text-align:center">
<button onclick="fun()"> <h2>CLICK ME!</h2></button>
<h2><p id="g"></p></h2>
<script type = "text/javascript">
function fun() {
let string = prompt('Enter a string: ');
if(string!=null)
{
[Link]("g").innerHTML="WELCOME TO "+string;
}
}
</script>
<style>
body { background-color:pink;}
p { color:blue;}
h1{color:brown;}
h2{color:green;}
</style>
</body>
</html>
OUTPUT: