JS基础闯关大作战

第一关:
<script  type  = "text/javascript" >

      // 声明一个函数,求两个数的和,测试你声明的函数
      function  sum(a ,b){
          return  a+b ;
    }
    document.write (sum( 2 , 3  ));

</script>


第二关:
<script  type  = "text/javascript" >

      // 声明一个函数,求任意个数的和,测试你声明的函数
    document.write (sum( 2 , 3  , 7 )+ "<br />"  );
    document.write (sum( 2 , 3  , 7 , 4 , 3  , 1 )+ "<br />"  );
    document.write (sum( "Hello"  , " " , "Tom"  )+ "<br />" );
    
      function  sum () {
          var  result =  0 ;
          // 函数实际调用执行时传入的参数,可以从  arguments 伪数组中获取
          for ( var  i =  0  ; i < arguments.length ; i++) {
            result += arguments [i];
         }
          return  result;
    }

</script>


第三关:

<script  type  = "text/javascript" >

      // 已有函数如下
      function  fun01(){
          return  [ 23 , true  , " 恭喜通过第  03 !"  ];
    }
    
      // 如何得到 " 恭喜通过第  03 !" 
    document.write (fun01()[ 2 ]);

</script>

第四关:
<script  type  = "text/javascript" >

      // 已有函数如下
      function  fun01(){
          return  {
            stuName :  "Tom" ,
            stuAge :  12 ,
            stuWords :  " 恭喜通过第  04 !"
         };
    }
    
      // 如何得到 " 恭喜通过第  04 !" 
    document.write (fun01().stuWords);

</script>



第五关:

<script  type  = "text/javascript" >

      // 已有函数如下
      function  fun01(){
          return  function  (){
              return  "  恭喜通过第  05 !"  ;
         };
    }
    
      // 如何得到 " 恭喜通过第  05 !" 
    document.write (fun01()());

</script>


第六关:

<script  type  = "text/javascript" >

      // 已有函数如下
      function  fun01(){
          return  {
            sayHello :  function  (){
                  return  "  恭喜通过第  06 !"  ;
             }
         };
    }
    
      // 如何得到 " 恭喜通过第  06 !" 
    document.write (fun01().sayHello());

</script>

第七关:
   <script  type  = "text/javascript" >

      // 已有函数如下
      function  fun01(){
          return  "abc"  ;
    }
    
    fun01.subFun =  function (){
          return  "  恭喜通过第  07 !"  ;
    }
    
      // 如何得到 " 恭喜通过第  07 !" 
    document.write (fun01.subFun ());

</script>    


第八关:
<script  type  = "text/javascript" >

      // 已有函数如下
      function  fun01(){
          return  "abc"  ;
    }
    
    fun01.subObj = {
        subFun :  function  (){
              return  "  恭喜通过第  08 !"  ;
         }
    };
    
      // 如何得到 " 恭喜通过第  08 !" 
    document.write (fun01.subObj.subFun ());

</script>

第九关:
<script  type  = "text/javascript" >

      // 已有函数如下
    ( function  (w ){
        w.jQuery =  function (){
              return  "  恭喜通过第  09 !"  ;
         };
    })(window);
    
      // 如何得到 " 恭喜通过第  09 !" 
    document.write (window.jQuery ());

</script>

第十关:
<script  type  = "text/javascript" >

      // 已有函数如下
    ( function  (w ){
        w.$ =  function (){
              return  {
                text :  function (){
                      return  "  恭喜通过第  10 !"  ;
                 }
             };
         }
    })(window);
    
      // 如何得到 " 恭喜通过第  10 !" 
    document.write ($().text());

</script>





第十一关;
<script  type  = "text/javascript" >

      // 已有函数如下
    ( function  (w ){
        w.$ =  function (){
              return  function (){
                  return  "  恭喜通过第  11 !"  ;
             };
         }
    })(window);
    
      // 如何得到 " 恭喜通过第  11 !" 
    document.write (window.$()());

</script>

第十二关:【boss来了···】
<script  type  = "text/javascript" >

      // 已有函数如下
    ( function  (w ){
        w.$ =  function (f){
              return  f();
         }
    })(window);
    
      function  sayHello(){
          return  "  恭喜通过第  12 !"  ;
    }
    
      // 如何得到 " 恭喜通过第  12 !"  ?不允许直接调用  sayHello
    document.write (window.$(sayHello));

</script>


第十三关:
<script  type  = "text/javascript" >
      // 已有函数如下
    ( function  (w ){
        w.$ =  function (id){
              return  core(document.getElementById (id));
         }
        
          function  core(dom ){
              var  obj = {
                    element : dom,
                    text :  function  () {
                          return  this.element.firstChild.nodeValue;
                     }
                 };
            obj.text ();
              return  obj;
         }
        
    })(window);

    window.onload =  function (){
        
          // 如何得到 " 恭喜通过第  13 !" 
        alert ($( "btn"  ).text ());
    }

</script>
</head>
<body>

     <button  id = "btn" >  恭喜通过第 13   ! </button>

</body>
</html>


第十四关:【大boss】

<script  type  = "text/javascript" >
      // 已有函数如下
    ( function  (w){
        w.$ =  function (argument){
              if (argument  instanceof  Function){
                window.onload = argument ;
             } else  if (argument  instanceof  String ||  typeof  argument ==  "string" ){
                  var  ele = document.getElementById(argument );
                  return  $(ele );
             } else  if (argument  instanceof  Element){
                  return  {
                    ele : argument ,
                    text :  function (){
                          return  this.ele.firstChild.nodeValue;
                     }
                 };
             }
         }
    })(window);
    
      // 如何在页面加载完成时得到“恭喜通过第  14 !  ”?
    $( function  (){
        alert ($( "btn"  ).text ());
    });
    
      /* window.onload = function(){
        alert("ttt");
    }; */

</script>
</head>
<body>

     <button  id = "btn" >  恭喜通过第 14   ! </button>

</body>






第十四关:【终极boss】

<script  type  = "text/javascript" >
      // 已有函数如下
    ( function  (w){
        w.$ =  function (argument){
              if (argument  instanceof  Function){
                window.onload = argument ;
             } else  if (argument  instanceof  String ||  typeof  argument ==  "string" ){
                  var  ele = document.getElementById(argument );
                  return  $(ele );
             } else  if (argument  instanceof  Element){
                  return  {
                    ele : argument ,
                    text :  function (){
                          return  this.ele.firstChild.nodeValue;
                     },
                    click :  function (callBack){
                        this.ele.onclick = callBack ;
                     }
                 };
             }
         }
    })(window);
    
      // 如何在点击按钮后弹出“恭喜通过第  15 !  ”?
    $( function  (){
        $ ( "btn"  ).click ( function (){
            alert ($( this  ).text ());
              //this.firstChild.nodeValue;
         });
          /* ele.onclick = function(){
            
        }; */
    });

</script>


------恭喜你顺利通关!----


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值