Page 214 - Web_Application_v2.0_C12_Fb
P. 214
// Check if user entered a name
if (userName) {
document.write("Hello, " + userName + "! Welcome to our website.");
}};
MyFunc();
</SCRIPT>
</BODY>
</HTML>
Output:
Example 25: To create a function to find the smallest out of 3 numbers
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Find Smallest of Three Numbers</TITLE>
</HEAD>
<BODY>
<H2>Smallest of Three Numbers</H2>
<SCRIPT>
// Function to find the smallest number
function findSmallest(a, b, c) {
var smallest = a;
if (b < smallest) {
smallest = b;
}
if (c < smallest) {
smallest = c;
}
return smallest;
}
var result = findSmallest(15,7, 22);
// Output using document.write
document.write("The smallest number is: " + result);
</SCRIPT>
</BODY>
</HTML>
212 Touchpad Web Applications (Ver. 2.0)-XII

