Page 378 - Web_Application_v2.0_C12_Fb
P. 378
Output of the preceding code is as follows:
9. Write JavaScript code to accept a user's name in a prompt and use the concat() function to display
'Welcome' followed by the user's name!.
Ans. <!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Greeting Page</TITLE>
</HEAD>
<BODY>
<P ID="W1"></P>
<BUTTON ONCLICK="displayGreeting()">SHOW GREETING</BUTTON>
<SCRIPT>
function displayGreeting() {
let name = prompt("Please enter your name:");
let greeting = "Welcome " .concat(name, "!");
document.getElementById("W1").innerHTML = greeting;
}
</SCRIPT>
</BODY>
</HTML>
Output of the preceding code is as follows:
376 Touchpad Web Applications (Ver. 2.0)-XII

