Answer the question
In order to leave comments, you need to log in
Why is the condition in the loop not being met?
function chooseOptExpenses() {
for (let i = 0, c = 2; i < c; i++) {
let expenses = prompt("Введите количество необязательных статей расходов в этом месяце", '');
console.log(expenses);
if (typeof (expenses) === isNaN && typeof (expenses) == null
&& expenses == "") {
c++;
alert("Введите количество расходов", '');
}
}
Answer the question
In order to leave comments, you need to log in
typeof prompt('aaa') will always be 'string', you don't even need to check anything there
good morning.
Do you need to make sure that the entered value is a number?
If so, then it is easier for you to set this condition.
if (typeof +expenses !== 'number' ) {
//...
}
where "+" is a cast to Number type. You can use parseInt(n);
Now, in principle, logically:
Let's say that your condition checks for the NaN type (and not the isNaN (n) function) and typeof returns not a string, then I want to pay attention to the logical operator && (AND), which, if it matches the condition, will return false , since NaN !== null && (and) null !== 'empty string',
so in each condition you check the result of typeof (...) - i.e. a string with data type other than string (returned by typeof )
The curly brace closing the body of the function is missing.
As I understand it, you wanted to call sequentially and write down two values \u200b\u200btransmitted by the user, in this case you can do without a loop.
Promise || conditional statements.
That is, when you click, you offer to write down the value, process it (successful case and unsuccessful case) and then checking whether the first step has been taken, you offer to write the second value again into a new variable. Thus, you have 2 values in different variables, which you can later operate as you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question