Skip to content

Error in the solution to Exercise 3.4 #1138

@KrNor

Description

@KrNor

Exercise 3.4 states:

...if an account is accessed more than seven consecutive times with an incorrect password, it invokes the function call_the_cops.

The current solution accounts for total, not consecutive atempts with an incorrect password.

I suggest resetting the counter to 0 after the account is accessed with a correct password.

function dispatch(m, q) {
    if (invalid_attempts < 7) {
        if (p === q) {
            invalid_attempts = 0; // added
            return m === "withdraw"
                   ? withdraw
                   : m === "deposit"
                   ? deposit
                   : "Unknown request: make_account";
        } else {
            invalid_attempts = invalid_attempts + 1;
            return x => "Incorrect Password";
        }
    } else {
        return calling_the_cops;
    }
}

And adding a commented out successful request:

...
a("withdraw", "rosebad")(50);
// a("withdraw", "rosebud")(50);
a("withdraw", "rosebad")(50);
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions