2014年8月25日月曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 7(Types, Equality, Conversion and All That Jazz: Serious types)、SHARPEN YOUR PENCIL(p.293)を解いてみる。

SHARPEN YOUR PENCIL(p.293)

コード(BBEdit, Emacs)

var lieDetectorTest = function () {
        var lies = 0,
            stolenDiamond = {},
            car = {
                keysInPocket: null
            },
            foundYouAtTheCrimeScene = [],
            yourName = ' ',
            output = '';
        
        // true
        if (stolenDiamond) {
            print('You stole the diamond');
            lies += 1;
        }
        // false
        if (car.keysInPocket) {
            print('Uh oh, guess you stole the car!');
            lies += 1;
        }
        // false
        if (car.emptyGasTank) {
            print('You drove the car after you stole it!');
            lies += 1;
        }
        // true
        if (foundYouAtTheCrimeScene) {
            print('A sure sign of guilt');
            lies += 1;
        }
        // false
        if (foundYouAtTheCrimeScene[0]) {
            print('Caught with a stolen item!');
            lies += 1;
        }
        // true
        if (yourName) {
            print('Guess you lied about your name');
            lies += 1;
        }
        return lies;
    },
    numberOfLies;

numberOfLies = lieDetectorTest();
print('You told ' + numberOfLies + ' lies!'); // 3

// true
if (numberOfLies >= 3) {
    print('Guilty as charged');
}












						

0 コメント:

コメントを投稿