Page 276 - Web Applications (803) Class 12
P. 276
else
nstr += “#”;
}//for loop ends
// Display the length and the modified string in an alert box
alert(“Length of the string: “ + length + “\nModified string: “ + nstr);
}
</script>
</body>
</html>
Output:
9. Write a function in JavaScript that displays a prompt box which accepts a name and displays a greeting “Welcome
<name>!” in a paragraph which has an id “W1”.
Ans. <!DOCTYPE html>
<html>
<head>
<title>Display Greeting</title>
</head>
<body bgcolor=”red” text=”white”>
<h1>Display Greeting</h1>
<button onclick=”display()”>Click Here</button>
<p id=”W1”></p>
<script>
function display() {
var tname = prompt(“Enter your name:”);
if (tname !== null) {
274 Touchpad Web Applications-XII

