我要怎么转向这个正确的方向。使用 if 语句以正确的方式将数据从提示符获取到控制台

how am i going to turn this right way. get data from prompt to console using if statement the right way

无论我在提示字符串或数字中传递什么,它都会返回为 'welcome to the dashboard',即使我输入的是字符串而不是数字。

let user = prompt('user name:');
let id = prompt('user id:');

let dev = parseInt(id);


if (typeof user === 'undefined' || dev.length === 0) {
  console.error('you miss one of the inputs.');

} else if (typeof user === 'string' && typeof dev === 'number') {
  console.log('welocme on yto your dashboard.');
} else {
  console.log('either user name or ID  is wrong please check again');
}

prompt returns a String,可以裁剪(去掉前后的空格)。然后您可以检查字符串的长度是否为 0,并检查 dev 是否正确解析了 id 的值:

let user = prompt('Username:').trim();
let id = prompt('User ID:').trim();

let dev = parseInt(id);

if (!(user && id)) {
  console.error('You missed one of the inputs.');
} else if (!isNaN(dev)) {
  console.log('Welcome to your dashboard.');
} else {
  console.error('Either your username or ID is wrong. Please check again.');
}