These are the lines in your code where the minimum value is being set by the user:
let min = prompt("Enter a Minimum Value:");
Min=min;
You used the “prompt” function to set the minimum value.
Since prompt() returns a string value, “Min
” becomes set to a string rather than a number.
When you add up a string with another variable, you get a string in return.
Example:
alert("ABC"+(23+10)) // output: "ABC33"
alert("ABC"+23+10) // output: "ABC2310"
There are different ways to change a string into a number.
The simplest is probably using the Number("...")
function.
alert(Number("10")+23+10) // output: 43
The method that I like using is multiplying the string by 1.
alert(("10"*1)+23+10) // output: 43
^ I only prefer this method bc it’s less typing
Either way works.
For now, try using this in your project:
let min = Number(prompt("Enter a Minimum Value:"));
Min=min;
Also, if a user types letters or something other than a number in the prompt, the minimum value will be set to NaN
(Not a Number).
Here's how to fix that
let min = Number(prompt("Enter a Minimum Value:"));
if(!isNaN(min))
Min=min;
Let me know if it works