2015年1月26日月曜日

開発環境

  • OS X Yosemite - Apple (OS)
  • Safari, Firefox, Google Chrome(Webプラウザ)
  • Emacs (CUI)、BBEdit - Bare Bones Software, Inc.(GUI) (Text Editor)
  • JavaScript (プログラミング言語)

Head First jQuery(Ryan Benedetti(著)、Ronan Cranley(著)、O'Reilly Media)のChapter 3(JQuery Events and Functions: Making Things Happen on Your Page)、JQUERY MAGNETS(No. 1755)を解いてみる。

その他参考書籍

JQUERY MAGNETS(No. 1755)

JavaScript(BBEdit, Emacs)

scripts/my_script1755.js

$(document).ready(function (){
    var getRandom = function (num){
            var result = Math.floor(Math.random() * num);

            return result;
        },
        checkForCode = function (){
            var discount = getRandom(6) + 5,
                discount_msg = '<p>Your Discount is ' + discount + '%</p>';

            $(this).append(discount_msg);
            $('.guess_box').each(function() {
                $(this).unbind('click');
            });
        },
        hideCode = function (){
            var numRand = getRandom(4);

            $('.guess_box').each(function(index, value) {
                if (numRand === index) {
                    $(this).append('<span id="has_discount"></span>');
                    return false;
                }
            });
        };
    
    $('.guess_box').click(checkForCode);
});

0 コメント:

コメントを投稿