return ends a function. That means that any code within the function and after the return does not get executed:
console.log("foo");//Gets logged on function call
return "bar";//this is what the function returns
console.log("This won't be printed");//This does not get printed-it is after the return
Because you have a
return in the second example, you need to do something with that return. A return will return the value provided to it, which means you can store the result of a function in a variable, and do other things like that with it:
let var1 = foo();
console.log(var1);//will print "foo"
So, in order for you to view ‘rock’ when calling the second function, you would have to
console.log(getUserChoice("rock");//this will now print "rock", because you are utilising the return of the function.
When calling a function, if you print a function with no return, the result is
undefined (because you are printing nothing-no return, no value to print), conversely, if you only call a function, but not print it, you will get nothing:
foo();//This won't print anything because all you are doing is getting the value the function is returning, but not doing anything with it.
console.log(foo());//This prints "foo"
console.log(bar());//This will print undefined as there is no value being returned from the function.
bar();//This will print 'bar', as that is what the function does.
I hope this helps!