0

Passing object to function is not working.


function getSecret(file, secretPassword){
    file.opened = file.opened + 1;
    if(secretPassword == file.password){
        return file.contents;
    }
    else {
        return "Invalid password! No secret for you";
    }
}

function setSecret(file, secretPassword, secret){
    if(secretPassword == file.password){
        file.opened = 0;
        file.contents = secret;
    }
}

var superSecretFile = {
    level: "classified",
    opened: 0,
    password: 2,
    contents: "Dr. Evel's next meeting is in Detroit."
};
var secret = getSecret(superSecretFile, superSecretFile.password);** why  superSecretFile.password is not passing the value 2
console.log(secret);

setSecret(superSecretFile,2, "Dr. Evel's next meeting is in Philadelphia.");
secret = getSecret(superSecretFile, superSecretFile.password);
console.log(secret);

I am passing an object as an argument. This code doesn't work if I put superSecretFile.password. Why it doesn't?

mnille
  • 1,328
  • 4
  • 16
  • 20

0 Answers0