Function-2

 

In this example, We will pass parameter to JavaScript function and print the result based on parameter value passed. Here is the method: function greetings(f) { var message = ""; if(f == 1) message = "Good morning"; else if(f == 2) message = "bye bye"; return message; } See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p id="sample"></p> <script> function greetings(f) { var message = ""; if(f == 1) message = "Good morning"; else if(f == 2) message = "bye bye"; return message; } document.getElementById("sample").innerHTML = greetings(1); </script> </body> </html>
Output