0% found this document useful (0 votes)
81 views4 pages

Multiplication Table

The document contains code to generate a multiplication table using JavaScript. It prompts the user to input the number of rows and columns, then uses a for loop within a while loop to dynamically create a HTML table with the multiplication results. It also includes code for several other JavaScript exercises: displaying the current day and time, calculating the area of a triangle, determining if a year is a leap year, converting between Celsius and Fahrenheit temperatures, and alphabetically sorting the letters of a string.

Uploaded by

fcmitc
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)
81 views4 pages

Multiplication Table

The document contains code to generate a multiplication table using JavaScript. It prompts the user to input the number of rows and columns, then uses a for loop within a while loop to dynamically create a HTML table with the multiplication results. It also includes code for several other JavaScript exercises: displaying the current day and time, calculating the area of a triangle, determining if a year is a leap year, converting between Celsius and Fahrenheit temperatures, and alphabetically sorting the letters of a string.

Uploaded by

fcmitc
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/ 4

1.

Multiplication Table
<html>
<head>
<title>Multiplication Table</title>
<script type="text/javascript">
var rows = prompt("How many rows for your multiplication table?");
var cols = prompt("How many columns for your multiplication table?");
if(rows == "" || rows == null)
rows = 10;
if(cols== "" || cols== null)
cols = 10;
createTable(rows, cols);
function createTable(rows, cols)
{
var j=1;
var output = "<table border='1' width='500' cellspacing='0'cellpadding='5'>";
for(i=1;i<=rows;i++)
{
output = output + "<tr>";
while(j<=cols)
{
output = output + "<td>" + i*j + "</td>";
j = j+1;
}
output = output + "</tr>";
j = 1;
}
output = output + "</table>";
document.write(output);
}
</script>
</head>
<body>
</body>
</html>

2. 1. Write a JavaScript program to display the current day and time in the following format. Go
to the editor

Sample Output : Today is : Tuesday.

Current time is : 10 PM : 30 : 38

var today = new Date();

var day = today.getDay();


var daylist = ["Sunday","Monday","Tuesday","Wednesday
","Thursday","Friday","Saturday"];

console.log("Today is : " + daylist[day] + ".");

var hour = today.getHours();

var minute = today.getMinutes();

var second = today.getSeconds();

var prepand = (hour >= 12)? " PM ":" AM ";

hour = (hour >= 12)? hour - 12: hour;

if (hour===0 && prepand===' PM ')

if (minute===0 && second===0)

hour=12;

prepand=' Noon';

else

hour=12;

prepand=' PM';

if (hour===0 && prepand===' AM ')

if (minute===0 && second===0)

hour=12;

prepand=' Midnight';

else
{

hour=12;

prepand=' AM';

console.log("Current Time : "+hour + prepand + " : " + minute + " : " + second);

Write a JavaScript program to find the area of a triangle where lengths of the three of its sides are 5,
6, 7.

var side1 = 5;

var side2 = 6;

var side3 = 7;

var s = (side1 + side2 + side3)/2;

var area = Math.sqrt(s*((s-side1)*(s-side2)*(s-side3)));

console.log(area);

Write a JavaScript program to determine whether a given year is a leap


year in the Gregorian calendar.
function leapyear(year)

return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0);

console.log(leapyear(2016));

console.log(leapyear(2000));

console.log(leapyear(1700));

console.log(leapyear(1800));

console.log(leapyear(100));

Write a JavaScript program to convert temperatures to and from Celsius,


Fahrenheit.
function cToF(celsius)
{

var cTemp = celsius;

var cToFahr = cTemp * 9 / 5 + 32;

var message = cTemp+'\xB0C is ' + cToFahr + ' \xB0F.';

console.log(message);

function fToC(fahrenheit)

var fTemp = fahrenheit;

var fToCel = (fTemp - 32) * 5 / 9;

var message = fTemp+'\xB0F is ' + fToCel + '\xB0C.';

console.log(message);

cToF(60);

fToC(45);

Write a JavaScript program to convert the letters of a given string in


alphabetical order.
function alphabet_Soup(str) {

return str.split("").sort().join("");

console.log(alphabet_Soup("Python"));

console.log(alphabet_Soup("Exercises"));

You might also like