Just started a javascript course. What is the benefit of using a function for the following script. Verses living the function off. It appears to do the same thing.

<title> Greeting </title>
function greet(who){
alert ("Hello, "+ who + '' + who2);
var who = prompt ("what is your first name");
var who2 = prompt ("what is your last name");
alert("Hello " + who + ' ' + who2);