Hi. Why “else”, where function is calling isn’t work when I enter correct a and b? And 2nd question is how to make such action shorter?
‘use strict’;
let a = prompt(“Your name?”,’’),
b = prompt(“yor age?”,’’);
function user(name,age){
alert('Имя пользователя: ’ + name);
alert('Возраст: '+ age);
};
if ((a || b == null)||(a && b==null)||(a || b == ‘’)||(a && b==’’))
{
alert(‘Not Correct!’);
} else {
user(a,b);
};
WOOOOOOOOOOOOOOOOOOOOOOW!!!!!

In repl i got some issues with quotations, so that might cause additional problem for you.
Beside that… You dont need all of those checking in your if statement.
if (!a || !b)
would do the job. It checks if either input of a was falsy or input of b was falsy and alerts Not correct.
There is code with console logs instead of alerts:
let a = prompt("Your name?",""),
b = prompt("yor age?",);
function user(name,age){
console.log('Имя пользователя:' + name);
console.log('Возраст: '+ age);
};
if (!a || !b) {
console.log("Wrong input")
} else {
user(a,b);
};
1 Like
((a || b == null)||(a && b==null)||(a || b == ‘’)||(a && b==’’))
The above is your problem. You can’t do combined conditional evaluations like that. This conditional translates to:
if
-
a
is truthy OR b
is equal to null
OR
-
a
is truthy AND b
is equal to null
OR
-
a
is truthy AND b
is an empty string
Thanks for answer, “!” is working, but I want to understand, what is wrong in my “if”?
so i need to combine (a||b)?
It depends on what you are trying to achieve.
(a || b)
is “If a
is truthy OR b
is truthy.”
1 Like