0

I want to return the password of a user's account if they have a password. If not I want it to return undefined.

EDIT: The user is an account holder for a website, the password is the password to gain entry to their account.

My attempt:

function retrievePassword(user) {
    if (user = password) {
    return password;
} else {
    return '';
}}

I believe my problem lies in the secound line. I want to say if the user CONTAINS or HAS or POSSESES a password, then return it. I am sure that user = password is not communicating that, but I haven't a clue how you are supposed to say that.

kylehink97
  • 11
  • 3
  • 1
    Are you looking for the [`in`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in) operator? – kelsny Jan 18 '23 at 19:22
  • 1
    `if (user.password)`, if you are talking about object properties? – Bergi Jan 18 '23 at 19:22
  • There is a problem with `if (user = password)`; `=` is an assignment statement, not an equality check. – mykaf Jan 18 '23 at 19:22
  • "*If not I want it to return undefined.*" - do you refer to the function or to the expression? Because the function does never return `undefined`. – Bergi Jan 18 '23 at 19:23
  • the in operator appears to be what I am looking for however I have just tried it to no avail. This is my attempt: – kylehink97 Jan 18 '23 at 19:26
  • if ('password' in user === true) { return password; } else { return ''; }} – kylehink97 Jan 18 '23 at 19:26
  • 1
    @kylehink97 Please [edit] your post and clarify your attempts. What exactly is `user`? What exactly is `password`? How exactly is `retrievePassword` used? – Sebastian Simon Jan 18 '23 at 19:27
  • 1
    Please [edit] your post. We need the descriptions in terms of _code_. – Sebastian Simon Jan 18 '23 at 19:30

0 Answers0