Javascript Basic: Example of Output: Today Is: Tuesday
Javascript Basic: Example of Output: Today Is: Tuesday
1. Write a JavaScript program to display the current day and time in the following format.
JS
HTML
<body>
<p></p>
<p>Click the button to print the current page.</p>
<button onclick="print_current_page()">Print this page</button>
</body>
JS
function print_current_page()
{
window.print();
}
Resualt:
JS
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10)
{
dd='0'+dd;
}
if(mm<10)
{
mm='0'+mm;
}
today = mm+'-'+dd+'-'+yyyy;
console.log(today);
today = mm+'/'+dd+'/'+yyyy;
console.log(today);
today = dd+'-'+mm+'-'+yyyy;
console.log(today);
today = dd+'/'+mm+'/'+yyyy;
console.log(today);
Resualt:
01-15-2022
01/15/2022
15-01-2022
15/01/2022
4.Write a JavaScript function to find the area of a triangle where the lengths of the three sides are 5,
6, 7.
var side1 = 5;
var side2 = 6;
var side3 = 7;
var perimeter = (side1 + side2 + side3)/2;
var area = Math.sqrt(perimeter*((perimeter-side1)*(perimeter-side2)*(perimeter-side3)));
console.log(area);
Resualt:
14.696938456699069