0% found this document useful (0 votes)
62 views6 pages

HTML

The document contains 6 programming problems involving JavaScript functions: 1. A script to find the greatest of three user-input numbers. 2. Two functions to calculate the circumference and area of a circle given the radius. 3. A function to count the number of elements in an array between 13 and 29. 4. An age calculator that displays age in days, months, and years from a date of birth. 5. A program to calculate the cost of a trip given miles, gas price, and miles per gallon. 6. A slideshow that displays images for 5 seconds each using buttons to navigate.

Uploaded by

Divakaran A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views6 pages

HTML

The document contains 6 programming problems involving JavaScript functions: 1. A script to find the greatest of three user-input numbers. 2. Two functions to calculate the circumference and area of a circle given the radius. 3. A function to count the number of elements in an array between 13 and 29. 4. An age calculator that displays age in days, months, and years from a date of birth. 5. A program to calculate the cost of a trip given miles, gas price, and miles per gallon. 6. A slideshow that displays images for 5 seconds each using buttons to navigate.

Uploaded by

Divakaran A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Write a script to take three numbers from the user and display the greatest number out of
three.
Code:
<html>
<head>
<script>
function largest()
{
var num1, num2, num3;
num1 = Number(document.getElementById("N").value);
num2 = Number(document.getElementById("M").value);
num3 = Number(document.getElementById("O").value);
if(num1>num2 && num1>num3)
{
window.alert(num1+"-is greatest");
}
else if(num2>num1 && num2>num3)
{
window.alert(num2+"-is greatst");
}
else if(num3>num1 && num3>num1)
{
window.alert(num3+"is greatest");
}
}
</script>
</head>
<body>
<h1>Calculate largest among three numbers</h1>
<hr color="cyan">
<br>
Enter number 1: <input type="text" id="N"></input><br>
Enter number 2: <input type="text" id="M"></input><br>
Enter number 3: <input type="text" id="O"></input><br>
<hr color="cyan">
<center><button onclick="largest()">OK</button>
</body>
</html>
OUTPUT:
2. Create two functions that calculate properties of a circle. Create a function called
calcCircumfrence to Pass the radius to the function and Calculate the circumference based
on the radius and output "The circumference is NN". Create a function called calcArea to
Pass the radius to the function. Calculate the area based on the radius, and output "The
area is NN".

Code:

<!DOCTYPE html>

<html>

<head>

<title>Area Of Circle and Circumference</title>

</head>

<body>

<script>

function calcCircumference()

var r=document.getElementById('n1').value;

var calc=2*22/7*r;

document.getElementById('output1').innerHTML="Circumferenceof Circle is "+calc;

function calcArea()

var r=document.getElementById('n1').value;

var area=22/7*r*r;

document.getElementById('output2').innerHTML="Area of Circleis"+area;

</script>

Enter the Radius:<input type="text" id="n1" name="radius" placeholder>

<br>

<button type="button"onclick="calcCircumference()">

Circumference</button>

<button type="button" onclick="calcArea()">Area</button>

<br>
<p id="output1"></p>

<p id="output2"></p>

</body>

</html>

OUTPUT:

3. Complete the following function called Count that takes an array of integers and the size
of the array, and return the number of items in the array that is greater than 13 and less
than 29.
CODE:
<!DOCTYPE html>
<html>
<head>
<title>Count the array Of Integers</title>
</head>
<body>
<script type="text/javascript">
function Count()
{
var arr=new Array(48,36,15,14,3,8,24,6,18,79,26,29,13);
for(var i=0;i<arr.length;i++)
{
if(arr[i]>13 && arr[i]<29)
{
var data=arr[i];
document.getElementById('output').append(data+" ,");
}
}
}
</script>
Integer Data In Array:48,36,15,14,3,8,24,6,18,79,26,29,13 <br>
<button type="button" onclick="Count()">
Count Numbers</button>
<div id="output">
</div>
</body>
</html>

OUTPUT:

4. Write a JavaScript to implement Age calculator which displays age in days, months
and years.

CODE:
<!DOCTYPE html>
<html>
<head>
<title>Age CAlculator</title>
</head>
<body>
<h2>Age Calculator</h2>
<label for="dob"> Date Of Birth: </label>
<input type="date" id="date_of_birth">
<input type="button" value="Calculator age" onclick="ageCalculator()">
<h3>Age:</h3>
<div id="age">
</div>
<script src="4.js">
</script>
</body>
</html>

$(document).ready(function(){
$("#calculate").click(function(){
var mdate = $("#birth_date").val().toString();
var yearThen = parseInt(mdate.substring(0,4), 10);
var monthThen = parseInt(mdate.substring(5,7), 10);
var dayThen = parseInt(mdate.substring(8,10), 10);

var today = new Date();


var birthday = new Date(yearThen, monthThen-1, dayThen);

var differenceInMilisecond = today.valueOf() - birthday.valueOf();

var year_age = Math.floor(differenceInMilisecond / 31536000000);


var day_age = Math.floor((differenceInMilisecond % 31536000000) /
86400000);
if ((today.getMonth() == birthday.getMonth()) && (today.getDate() ==
birthday.getDate())) {
alert("Happy B'day!!!");
}

var month_age = Math.floor(day_age/30);

day_age = day_age % 30;

if (isNaN(year_age) || isNaN(month_age) || isNaN(day_age)) {


$("#exact_age").text("Invalid birthday - Please try again!");
}
else {
$("#exact_age").html("You are<br/><span id=\"age\">" + year_age + " years
" + month_age + " months " + day_age + " days</span> old");
}
});
});
OUTPUT:

5. Write a program that reads number of miles, cost of a gallon of gas, and car gas
consumption (miles per gallon) and then determines the cost of a specific trip. The
output should be displayed using document.writeln
Code:

6. Design a HTML page to generate an image slide show using Javascript. First input
all the images(minimum of 5 images) you want to add to the slideshow. Add a
button to start the slideshow. Repeatedly starting from the first to last, display
each image for 5 seconds and then display the next image. Add two buttons to
view the previous and next image.
Code:

You might also like