I need help with a function I'm trying to construct. The purpose of this function is to determine if the input provided by the user in the boxes is an integer or not, and then print out the appropriate commentary. However, I am encountering an issue at the second level of the function where the "if" statement is failing to check if figure1 is a number (it doesn't output anything), while the "else if" and "else" statements are working fine. Can someone please assist me in identifying what might be wrong with my function?
function show() {
//Variable contains the value of field1 from input html which has been read thanks to onclick
var figure1 = document.getElementById("field1").value;
//Variable contains the value of field2 from input html which has been read thanks to onclick
var figure2 = document.getElementById("field2").value;
//empty until the instruction write in something
let sign = "";
//STEP 1
//loop working until the value of i reach the value of figure2
for (i = figure1; i <= figure2; i++)
{
if (Number(figure1) && Number(figure2)) {
//if both figure1 and figure2 are numbers, print the sign as follows - what sign contains from previous iteration + i + ", "
sign = sign + i + ", ";
} else {
if (Number(figure1)) {
//If statements from "if" level above haven't been fulfilled, print "Please, type integer in right-hand box";
sign = "Proszę wpisać liczbę w prawym polu";
} else if (Number(figure2)) {
//If statements from "if" level above haven't been fulfilled, print "Please, type integer in left-hand box";
sign = "Proszę wpisać liczbę w lewym polu";
} else {
sign = "Proszę wpisać wartości liczbowe w obu polach";
// If statements from "if"
// level above haven 't been fulfilled, print "Please, type integer in both boxes";
}
}
}
//podmienia wartość diva o id result na wartość zmiennej sign.
document.getElementById("result").innerHTML = sign;
}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="field1">
<!--W tym polu umieszczamy liczbę z przedziału-->
<input type="text" id="field2">
<!--W tym polu umieszczamy liczbę z przedziału-->
<input type="submit" value="pokaż" onclick="show()">
<!--Po kliknięciu zostaje wywołana funkcja "show()"-->
<div id="result"></div>
<!--wnętrze diva podmienimy przy użyciu funkcji "show()"-->
</body>