0% found this document useful (0 votes)
36 views14 pages

WT - Practicals 2

Uploaded by

Yuvraj jha
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)
36 views14 pages

WT - Practicals 2

Uploaded by

Yuvraj jha
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/ 14

Question 1. JavaScript Program to Print Hello World.

Answer
Here’s a simple JavaScript program to print "Hello World" to the console:
console.log("Hello World");
To run this code, you can either:
- Use a browser's developer tools (open the console and paste the code).
- Run it in a Node.js environment.

Question 2. JavaScript Program to Find the Factorial of a Number.


Answer
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
let number = 5;
let result = factorial(number);
console.log(`The factorial of ${number} is ${result}`);
Question 3. JavaScript Program to Find the greatest of 3 Numbers.
Answer
function findGreatest(num1, num2, num3) {
if (num1 >= num2 && num1 >= num3) {
return num1;
} else if (num2 >= num1 && num2 >= num3) {
return num2;
} else {
return num3;
}
}
let number1 = 10;
let number2 = 25;
let number3 = 15;
let greatest = findGreatest(number1, number2, number3);
console.log(`The greatest number is ${greatest}`);

Question 4. JavaScript Program to display the usage of all 3 dialog boxes.


Answer
alert("This is an alert dialog box!");
let userConfirmation = confirm("Do you want to proceed?");
if (userConfirmation) {
console.log("User chose OK.");
} else {
console.log("User chose Cancel.");
}
let userInput = prompt("Please enter your name:");
if (userInput) {
console.log(`Hello, ${userInput}!`);
} else {
console.log("No name was entered.")
}

Question 5. JavaScript Program to Call function code from links.


Answer
<!DOCTYPE html>
<html>
<head>
<title>Call Function from Link</title>
<script>
function sayHello() {
alert("Hello! You clicked the link.");
}

function showDate() {
alert("Current Date and Time: " + new Date());
}
</script>
</head>
<body>

<a href="#" onclick="sayHello(); return false;">Click me to say Hello</a><br>


<a href="#" onclick="showDate(); return false;">Click me to show Date and Time</a>

</body>
</html>

Question 6. JavaScript Program to Call function code from image-maps.


Answer
<!DOCTYPE html>
<html>
<head>
<title>Call Function from Image Map</title>
<script>
function clickArea(area) {
alert("You clicked on the " + area + " area!");
}
</script>
</head>
<body>

<h2>Clickable Image Map</h2>

<img src="https://via.placeholder.com/400x300" alt="Example Image" usemap="#image-map"


width="400" height="300">
<map name="image-map">
<!-- Each area defines a clickable region on the image -->
<area shape="rect" coords="34,44,270,350" alt="Left Area" href="#" onclick="clickArea('left');
return false;">
<area shape="circle" coords="337,300,44" alt="Right Area" href="#" onclick="clickArea('right');
return false;">
<area shape="poly" coords="290,172,333,250,255,251" alt="Triangle Area" href="#"
onclick="clickArea('triangle'); return false;">
</map>

</body>
</html>
Question 7. JavaScript Program to Find square of a Number.
Answer
Question 8. JavaScript Program to Find square root of a Number.
Answer

Question 9. JavaScript Program to show the usage of date functions.


Answer
Question 10. JavaScript Program to show the usage of string functions.
Answer
Question 11. JavaScript Program to implement event handling onclick, onmouseover, onmouseout
events.
Question 12. Program to show the usage of inline CSS using font styling.
Answer
Question 13. Program to show the usage of external CSS using text styling.
Question 14. Program to show the usage of internal CSS using text styling.
Answer

You might also like