Trying to get textbox input and output working

The core js function and console output works when the nText var is set manually (var nText = "exampleText" for instance) but I’m trying to make it take textbox input, perform the function, and then spit the result back out into the same textbox but I’m stuck on getting that to work. Any help with this would be appreciated, I’m still fairly new to js and this is just a little personal project I’m trying to do for practice.

<label for="nText">Your Text:</label>
<input type="text" id="nText" name="nText"><br><br>
<button onclick="firstLetterUppercase (input = 'nText')">aLtErNaTe</button>
function firstLetterUppercase (input = 'nText') {
  var res = "";
  for (i=0; i < input.length; i++) {
     res += i % 2 == 0 ? input.charAt(i).toUpperCase() : input.charAt(i);
  return res;  

var nText = document.getElementById("nText").value;