I want to take an input and use it as a parameter of a function in javascript

function myfunc(num,fix){
  alert(num.toFixed(fix));
  }
  myfunc(2.222,2);

In the above code, 2.222 and 2 are hard-coded. I want to take these values from a user. I have tried the following solution but it seems that it can be run without parameters being involved.

let num_new=prompt("Enter a decimal number");
  let num=parseFloat(num_new);
  let fix=prompt("Enter the decimal places to be rounded");  
  function myfunc(num,fix){
  alert(num.toFixed(fix));
  }
  myfunc(num,fix);

the above code can also run by removing the parameters, I need help in finding out a solution in which the parameters are being input from user. Thanks alot

4 thoughts on “I want to take an input and use it as a parameter of a function in javascript”

  1. I like the helpful info you provide in your articles.
    I’ll bookmark your weblog and check again here regularly. I’m
    quite sure I will learn lots of new stuff right here!
    Good luck for the next!