Multiplication Table

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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