I seem to not be to pass all the tests:
function profileActivation(profile, reason) {
if (reason === "confirm status manually") {
profile.active = true;
}
if (profile.active) {
if (profile.reason) {
return "confirm status manually";
} else {
delete profile.reason;
return profile;
}
} else {
if (!profile.reason) {
return "confirm status manually";
} else {
profile.active = true;
return profile;
}
}
}
// 🧠profileActivation takes two arguments, profile and reason, which are an object and a string respectively
// The reason arg is only used -and therefore required- to deactivate profiles, not to activate them
// The profile arg has an `active` property holding a Boolean value
// * If profile is active, profileActivation deactivates it and writes a `reason` prop holding the reason
// * If profile is inactive, profileActivation activates it and deletes the `reason` prop from the object
// * In both cases the updated profile object is returned
// 🧠Edge cases:
// * If the profile is inactive but its `reason` prop is **missing**, return the string "confirm status manually"
// * If the profile is active but it has a `reason` prop, return the string "confirm status manually"
// * If the profile is **missing** an `active` prop, return the string "impossible to ascertain status"
// 🌟 HINT: to confirm the existence of a prop, check that its value is not undefined
Only passing 3 and four
2
Answers
Not sure why you are using the
reason
argument in the first line of the function – the description of the function never mentions using the reason to activate a profile!Your code also never returns
"impossible to ascertain status"
, so it’s like you completely ignored that edge caseThe way I would do it is to handle the edge cases first, and then handle activation/de-activation.
Anyway, here’s the code I came up with
Seems to do what is expected
Re comment that it doesn’t work – well, the following is your code and it fails exactly like you claim mine fails – i.e. you claim the following failures
perhaps you forgot to use my code?