Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NCC-JavaScript-Week#4

Irene Chang
November 04, 2015

 NCC-JavaScript-Week#4

NTUST Coding Club JavaScript Course Week#4 (2015.11.06)
For self-study only.

Irene Chang

November 04, 2015
Tweet

More Decks by Irene Chang

Other Decks in Education

Transcript

  1. ‣ 䮋䨞겗"OTXFS ‣ 㛇燊铃岁㔋 Ը ⴅ爚GVODUJPO ‣ 㛇燊铃岁❀ Ը 暟⟝PCKFDU

    ‣ TDSJQU ‣ 4VCMJNF5FYU ˋ ‣ %0.矦➝ ‣ )5.-ⰅꟌ ‣ %0.✲⟝&WFOU "HFOEB 2
  2. 1 for (var i = 2; i < 100; i

    ++) { 2 var isPrime = true; 3 for(var j = 2; j < i; j ++ ) { 4 if (i % j === 0) { 5 isPrime = false; 6 break; 7 } 8 } 9 if (isPrime) { 10 console.log(i); 11 } 12 } 鱒ⴀ_涸颶侸 4
  3. 䒊用♧⦐ꤏ⴪ 佞Ⰵ_涸颶侸 鱒ⴀ痧_갪 1 var prime =[]; 2 for( var

    i = 50; i <= 500; i++ ){ 3 for( var j = 2; j < i; j++ ){ 4 if( i % j === 0 ){ 5 break; 6 } 7 else{ 8 prime.push(i); 9 break; 10 } 11 } 12 } 13 14 for( var n = 20; n < 27; n++){ 15 console.log(prime[n]); 16 } 5
  4. 1 function fnName(x, y) { 2 // Do something 3

    }; Ⱘそⴅ侸 1 var fnName = function(x, y) { 2 // Do something 3 }; ⼣そⴅ侸 ⴅ䒭GVODUJPO 9
  5. 1 function add(x, y) { 2 var total = x

    + y; 3 console.log(total); 4 }; 5 6 add(3,4); // 輸出7 ㄎ〭 ⴅ䒭GVODUJPO 10
  6. 1 function add(x, y) { 2 var total = x

    + y; 3 return total ; // 回傳運算後的值 4 }; 5 add(3,4); // 直接呼叫沒有意義 6 var result = add(3,4); // 把值存起來 7 console.log(result * 10); // 輸出70 鸒䌢䧮⦛꨾銴GVODUJPO㔐⫄㛂遤䖕涸穡卓⢵⨞Ⱖ➮✲ ⴅ䒭GVODUJPO 11
  7. 1 function square(num) { 2 var result = num *

    num; 3 return result ; // 回傳運算後的值 4 }; 5 console.log(square(10)); // 輸出100 ⿮侸〳⟃⟤䠑ㄐそ⡎僽ⴽ䒚ⵌ鸮荈䊹鿪溏♶䥢 ⴅ䒭GVODUJPO 13
  8. 1 function countNumber() { 2 for(var i = 0; i

    <= 100; i++){ 3 console.log(i); 4 }; 5 }; 6 countNumber(); GVODUJPO♶♧㹁銴剤⿮侸《对⡹䟝銴麨䧭涸湡涸 ⴅ䒭GVODUJPO 參數的數量沒有實際上的限制,但還是盡量控制在 2~3 個左右 14
  9. 1 var objName = { 2 key: value, 3 key:

    value, 4 key: function(){ 5 //Do Something 6 }; 7 }; 暟⟝0CKFDU 21
  10. 1 var objName = { 2 key: value, 3 key:

    value, 4 key: function(){ 5 //Do Something 6 }; 7 }; 〳⟃䪾㿂䚍QSPQFSUZ 䟝䧭僽꣡㿂倴鑪暟⟝涸 隶侸欽⢵䲾鶤鑪暟⟝ 涸暶颶 暟⟝0CKFDU 22
  11. 1 var objName = { 2 key: value, 3 key:

    value, 4 key: function(){ 5 //Do Something 6 }; 7 }; 㿂䚍QSPQFSUZ  㶶⚮♶欽䒸贫  侸㶶  倰岁.FUIPE 岤䠑ㄐそ鿪剤ⴕ㣐㼭㻨㿂䚍莅㿂䚍⛓꟦欽鸊럊ⴕꟚ 暟⟝0CKFDU 23
  12. 1 var myself = { 2 name: "Irene", 3 age:

    19, 4 calling: function(){ 5 console.log('Calling to' + this.name + 'at' + this.phone); 6 }, 7 }; 暟⟝0CKFDU 24
  13. 1 function test(){ 2 console.log("JavaScript"); 3 } 4 test(); //

    呼叫函式 5 var objTest = { 6 test: function(){ 7 console.log("JavaScript"); 8 } 9 }; 10 objTest.test(); //呼叫⽅方法 ⴅ䒭'VODUJPOWT倰岁.FUIPE 28
  14. <html> <head> <title>NCC JavaScript</title> <script type="text/javascript"> alert("Hello World!"); </script> </head>

    </html> 欽⢵雊懳錒㐼濼麥䱺♴⢵僽䭸⟂珳铃鎊懳錒 㐼㽠剚䪾鸏♧媯殹⡲僽4DSJQU贖椚罜ꬌ)UNM TDSJQU 33
  15. )5.- 㛇劥卺圓 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body>

    <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> 46
  16. )5.- 㛇劥卺圓 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body>

    <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Ը %0$5:1&㹁纏鸏⦐俒⟝涸겳㘗僽)5.- 47
  17. )5.- 㛇劥卺圓 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body>

    <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Ը IUNM䲾鶤鸏⦐俒⟝僽)5.- 48
  18. )5.- 㛇劥卺圓 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body>

    <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Ը IFBE欽倴鋊眕ㄤ侮넓笪갤湱ꡠ涸须鎝 49
  19. )5.- 㛇劥卺圓 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body>

    <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Ը CPEZ㽠僽剚ツ植㖈笪갤♳涸Ⰹ㺂 50
  20. )5.- <h#> 標題 </h#> <h1> Heading 1 </h1> <h2> Heading

    2 </h2> <h3> Heading 3 </h3> <h4> Heading 4 </h4> <h5> Heading 5 </h5> <h6> Heading 6 </h6> 㣐㼭 ꅾ銴䚍 51
  21. %0.&WFOU 䌢鋅涸&WFOU 事件名稱 描述 onchange 內容被改變時,EX: select onclick 內容被點擊時 onmouseover

    滑⿏鼠滑到某物件上 onmouseout 滑⿏鼠滑離某物件上 onsubmit 表單被送出時 onerror 載⼊入圖⽚片或⽂文件錯誤時 65