2014年8月13日水曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 5(Understanding Objects: A trip to Objectville)、SHARPEN YOUR PENCIL(p.194)を解いてみる。

SHARPEN YOUR PENCIL(p.194)

コード(BBEdit, Emacs)

var getSecret = function (file, secretPassword) {
        file.opened += 1;
        if (secretPassword === file.password) {
            return file.contents;
        } else {
            return 'Invalid password! No secret for you.';
        }
    },
    setSecret = function (file, secretPassword, secret) {
        if (secretPassword === file.password) {
            file.opened = 0;
            file.contents = secret;
        }
    },
    superSecretFile = {
        level: 'classified',
        opened: 0,
        password: 2,
        contents: "Dr. Evel's next meeting is in Detroit."
    },
    secret;

secret = getSecret(superSecretFile, 2);
print(secret);

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










						

0 コメント:

コメントを投稿