Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
NCC-JavaScript-Week#3
Search
Irene Chang
October 28, 2015
Education
0
120
NCC-JavaScript-Week#3
NTUST Coding Club JavaScript Course Week#3 (2015.11.06)
For self-study only.
Irene Chang
October 28, 2015
Tweet
Share
More Decks by Irene Chang
See All by Irene Chang
前端初心者談,合作過程與學習經驗
irene84111
0
160
一手打造你的專屬網誌-Hexo 簡介及教學
irene84111
0
510
NCC-JavaScript-Week#7
irene84111
0
130
NCC-JavaScript-Week#6
irene84111
0
140
NCC-JavaScript-Week#5
irene84111
0
65
NCC-SublimeText-InstallationTutorial
irene84111
0
35
NCC-JavaScript-Week#4
irene84111
0
39
NCC-JavaScript-Week#2
irene84111
0
230
NCC-JavaScript-Week#1
irene84111
0
190
Other Decks in Education
See All in Education
Flinga
matleenalaakso
2
13k
The Task is not the End: The Role of Task Repetition and Sequencing In Language Teaching
uranoken
0
220
Comment aborder et contribuer sereinement à un projet open source ? (Masterclass Université Toulouse III)
pylapp
0
3.2k
Canva
matleenalaakso
0
470
1106
cbtlibrary
0
430
HTML5 and the Open Web Platform - Lecture 3 - Web Technologies (1019888BNR)
signer
PRO
1
2.6k
2409_CompanyInfo_Hanji_published.pdf
yosukemurata
0
640
Requirements Analysis and Prototyping - Lecture 3 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
850
LinkedIn
matleenalaakso
0
3.4k
ヘイトスピーチがある世界のコミュニケーション
ktanishima
0
390
Mathematics used in cryptography around us
herumi
2
370
寺沢拓敬 2024. 09. 「言語政策研究と教育政策研究の狭間で英語教育政策を考える」
terasawat
0
220
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
The Invisible Side of Design
smashingmag
298
50k
Thoughts on Productivity
jonyablonski
67
4.4k
Side Projects
sachag
452
42k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Become a Pro
speakerdeck
PRO
26
5k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Transcript
+BWB4DSJQU 8FFL !〵猰㣐玑䒭鏤鎙灇瑖爢 #Z*SFOF$IBOH 㛇燊铃岁✳
‣ 醳绢㛇燊铃岁✳։♲ ‣ 箻绢♲GPS JGFMTF ˋ ‣ 㛇燊铃岁♲ Ը 崩玑䱾ⵖ鶬㕖XIJMF
‣ 箻绢㔋XIJMF GPS ‣ 䮋䨞겗 ˋ ‣ 㛇燊铃岁㔋 Ը ⴅ䒭GVODUJPO ˋ ‣ 㛇燊铃岁❀ Ը 须俲㘗ⴽ暟⟝ "HFOEB
醳绢㛇燊铃岁✳։♲ 须俲㘗䢀ꤏ 崩玑䱾ⵖ哭⟝䒭JGFMTF FMTFJG 崩玑䱾ⵖ鶬㕖GPS
ꤏ "SSBZ
‣ 䖎㢵匌銯佞㖈♧饱꧌⚥盘椚 ꤏ"SSBZ 1 var names = ["JS","Python","Scratch"]; 2 var
number = [1, 3.14, 7749, 0.001]; 3 var mixed = [1, "Irene", 2015, "Hi"]; 4 var empty = [];
1 var mixed = ["JS",123,"Scratch"]; 2 console.log(mixed[0] == "JS"); //
true 3 console.log(mixed[1]); // 123 ꤏ"SSBZ ‣ 嫦♧갪鿪剤♧⦐管贫*OEFY ‣ 管贫䖰㨥CBTFEJOEFYJOH ‣ 㶶⚮⛳剤JOEFY涸嚌䙂
1 var doubleArray =[[1,2],["a","b"]]; 2 console.log(doubleArray[0]);// [1,2] 3 console.log(doubleArray[1][1]); //
"b" ꧱㾵ꤏUXPEJNFOTJPOBMBSSBZ ꤏ"SSBZ 4 console.log(doubleArray[1][2]); // undefined
1 var fruits =[1, 3, 2, "Orange", "Apple"]; 2 fruits.sort();
//按照數字⼤大⼩小、字⺟母順序排列 3 fruits.reverse(); //按照數字⼤大⼩小、字⺟母倒序排列 4PSUJOH3FWFSTJOH ꤏ"SSBZ
1 var fruits =["Mango", "Orange", "Apple"]; 2 fruits.shift(); //刪除第⼀一項 "Mango"
3 fruits.pop(); //刪除最後⼀一項 “Apple" 4 console.log(fruits); // ["Orange"] 4IJGUJOH1PQQJOH ꤏ"SSBZ
1 var fruits =["Orange", "Apple"]; 2 fruits.unshift("Kiwi"); //在第⼀一項加⼊入"Kiwi" 3 fruits.push("Lemon");
//在最後⼀一項加⼊入”Lemon" 4 console.log(fruits); 5 // ["Kiwi","Orange","Apple","Lemon"] 6OTIJGUJOH1VTIJOH ꤏ"SSBZ
崩玑䱾ⵖ哭⟝䒭 JGFMTF FMTFJG
JG FMTF 1 if(condition) 2 { 3 //若符合條件,就執⾏行這段{}裡⾯面的程式碼 4 }
5 else{ 6 //不符合條件,就執⾏行這段{}裡⾯面的程式碼 7 }
JG FMTFJG FMTF 1 if(condition) 2 { 3 //若符合條件,就執⾏行這段{}裡⾯面的程式碼 4
} 5 else if(condition) 6 { 7 /*不符合上⼀一個條件但符合這⼀一個條件, 8 就執⾏行這段{}裡⾯面的程式碼*/ 9 } 10 else{ 11 //其他條件都不符合,就執⾏行這段{}裡⾯面的程式碼 12 }
崩玑䱾ⵖ鶬㕖 -PPQ
갸⯓鏤㹁䱾ⵖ隶侸 剤佪哭⟝ 锅侮䱾ⵖ隶侸⧩ 鶬㕖-PPQ 鶬㕖♲㣐哭⟝
GPS 鏤㹁♧⟝✲䞕銴ꅾ醳⨞䎙妄 1 for(var i = start; i < end;
i++){ 2 // 做條件成⽴立的事 3 }
箻绢♲GPS JGFMTF " 宠㔔侸 # 宠Ⰽ侸剓㣐Ⱇ㔔侸 $ 'J[[#V[[
" 宠㔔侸 1. 請使⽤用者輸⼊入任意數字 2. 使⽤用 for 和 if 判斷該數字的因數
hint: % 取餘數=0 3. 輸出該數字之因數(包含1與本⾝身) IUUQTKTCJODPNYJEPIJFEJU KT DPOTPMF
# 宠Ⰽ侸剓㣐Ⱇ㔔侸 1. 請使⽤用者輸⼊入兩個數字,以空⽩白隔開 2. 轉換型態、建⽴立空 array 3. 使⽤用 for
和 if 判斷兩數最⼤大公因數 hint: Math.max(), .push() IUUQTKTCJODPN[FCJWJFEJU KT DPOTPMF
$ 'J[[#V[[ 1. 輸出 1 到 100 2. 如果是 3
的倍數就輸出 Fizz 3. 如果是 5 的倍數就輸出 Buzz 4. 如果同時是 3 和 5 的倍數就輸出 FizzBuzz hint:雙層迴圈 IUUQTKTCJODPNXPLVTJFEJU KT DPOTPMF
䮋䨞겗 " 鱒ⴀ_涸颶侸 # _涸颶侸鱒ⴀ痧_갪
1 for (var ; ; ) { 2 var isPrime
= true; 3 for(var ; ; ) { 4 if ( === ) { 5 isPrime = ; 6 break; 7 } 8 } 9 if ( ) { 10 console.log( ); 11 } 12 } 鱒ⴀ_涸颶侸
䒊用♧⦐ꤏ 佞Ⰵ_涸颶侸 鱒ⴀ痧_갪 1 var prime =[]; 2 for( ;
; ){ 3 for( ; ; ){ 4 if( ){ 5 break; 6 } 7 else{ 8 prime. ( ); 9 break; 10 } 11 } 12 } 13 14 for( ; ; ){ 15 console.log( ); 16 }
㛇燊铃岁♲ Ը 崩玑䱾ⵖ鶬㕖XIJMF
XIJMF 殹⡹♶濼麥鑪㛂遤䎙妄
XIJMF ♶倬ꅾ醳㛂遤♧⟝✲ 湬ⵌ痘ざ厥⦐哭⟝䩞⨢姺 1 while(condition){ 2 // 做條件成⽴立的事 3 }
锞⢪欽罏鱒Ⰵ♧⦐侸㶶OVN ⢪欽XIJMF鱒ⴀ։OVN 1 var num = prompt("輸⼊入數字"); 2 var i
= 0; 3 while(i < num){ 4 i++; 5 console.log(i); 6 } XIJMF
㼭鑑魨䩛 雊䧮⦛⢵梖枤侸㶶涸麉䨡 锞⢪欽罏鱒Ⰵ♧⦐➝倴_涸侸㶶 デ鏰⢪欽罏枤㼩✫㣖㣐䧴㣖㼭 銼鑉㉏湬ⵌ⢪欽罏枤㼩瘸呪
var secret = Math.floor((Math.random()*100)+1); ( ){ var guess = (
"A number between 1 and 100" ); if( == ){ console.log( 'You got it!' ); break; } ( ){ console.log( 'Smaller' ); } { console.log( 'Bigger' ); } } //noprotect
• 如果迴圈處理的條件從來都沒有符合過,就永 遠不會執⾏行迴圈。 • 如果⼀一直符合測試條件,便會造成無限迴圈。 鶬㕖-PPQ 岤䠑
箻绢♲XIJMF GPS " 宠ꥣ⛨籏ㄤ
" 宠ꥣ⛨籏ㄤ 1. 請使⽤用者輸⼊入任意數字 2. 使⽤用 while 計算階乘 3. 使⽤用
for 計算總和 IUUQTKTCJODPNNBRBKJFEJU KT DPOTPMF
㛇燊铃岁㔋 ⴅ䒭GVODUJPO
ⴅ䒭 'VODUJPO ➊랃〳⟃く㌨
㽠⫹掑跗票♧垺矦㋲
‣ ♶ず涸굺勞JOQVUT ‣ 湱ず涸捸掑倰䒭ㄤ麕玑GVODUJPO ‣ ♶ず涸跗票PVUQVUT ⡹♶剚䟝嫦妄掑跗票鿪銴䪾麕玑ⱄ㻨♧麒
1 function fnName(x, y) { 2 // Do something 3
}; Ⱘそⴅ侸 1 var fnName = function(x, y) { 2 // Do something 3 }; ⼣そⴅ侸 ⴅ䒭GVODUJPO
1 function add(x, y) { 2 var total = x
+ y; 3 console.log(total); 4 }; 5 6 add(3,4); // 輸出7 ㄎ〭 ⴅ䒭GVODUJPO
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
岤䠑 ⴅ䒭麂ⵌSFUVSO湱殹倴用⽰⨢姺䖕涸玑䒭 䨾⟃䧮⦛鸒䌢䪾SFUVSO佞㖈剓䖕罜⚂〫剤♧⦐ 䵩ꂂ崩玑䱾ⵖJGFMTF㽠〳⟃剤㥪䎙⦐SFUVSO 㥶卓ⴅ䒭尝剤鏤㹁SFUVSO㸐剚㔐⫄VOEFOFE
1 function square(num) { 2 var result = num *
num; 3 return result ; // 回傳運算後的值 4 }; 5 console.log(square(10)); // 輸出100 侸〳⟃⟤䠑ㄐそ⡎僽ⴽ䒚ⵌ鸮荈䊹鿪溏♶䥢 ⴅ䒭GVODUJPO
1 function countNumber() { 2 for(var i = 0; i
<= 100; i++){ 3 console.log(i); 4 }; 5 }; 6 countNumber(); GVODUJPO♶♧㹁銴剤侸《对⡹䟝銴麨䧭涸湡涸 ⴅ䒭GVODUJPO 參數的數量沒有實際上的限制,但還是盡量控制在 2~3 個左右
1 function areaBox(width, length) { 2 var result = width*length;
3 return result; 4 // 在 {} 裡的每⼀一⾏行⼀一定要⽤用 ; 結尾 5 }; 6 console.log(areaBox(12,24)); //288 ⴕ贫䖎ꅾ銴 ⴅ䒭GVODUJPO
D.R.Y %PO’U3FQFBU:PVSTFMG ,FFQZPVSTFMG 殹⡹涮植⡹♧湬ꅾ醳䩧ず垺涸玑䒭焺 ㈔♧⥜佖涸鿈ⴕ〫剤侸罜䊺齡⡹ 㽠䥰鑪⢪欽GVODUJPO
㛇燊铃岁❀ 须俲㘗ⴽ暟⟝
⡹䟝銴䒊用♧⦐匌銯 鸏⦐匌銯剤䖎㢵㿂䚍
%BUBUZQFそ㶶䎃룲欰傈䩛堥⥌盳耷噠 鼩剤 .FUIPE鸏⦐➃〳⟃⨞➊랃
暟⟝ 0CKFDU
暟⟝0CKFDU ♧⦐暟⟝僽♧❉㿂䚍涸꧌ざ 罜㿂䚍僽꒳莅⧩⛓涸ꡠ耢 LFZWBMVFQBJST
1 var objName = { 2 key: value, 3 key:
value, 4 key: function(){ 5 //Do Something 6 }; 7 }; " 暟⟝0CKFDU
1 var objName = { 2 key: value, 3 key:
value, 4 key: function(){ 5 //Do Something 6 }; 7 }; 〳⟃䪾㿂䚍QSPQFSUZ 䟝䧭僽꣡㿂倴鑪暟⟝涸 隶侸欽⢵䲾鶤鑪暟⟝ 涸暶颶 " 暟⟝0CKFDU
1 var objName = { 2 key: value, 3 key:
value, 4 key: function(){ 5 //Do Something 6 }; 7 }; 㿂䚍QSPQFSUZ 㶶⚮♶欽䒸贫 侸㶶 倰岁.FUIPE 岤䠑ㄐそ鿪剤ⴕ㣐㼭㻨㿂䚍莅㿂䚍⛓欽鸊럊ⴕ " 暟⟝0CKFDU
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
1 objectName.propertyName 《ⴀ㿂䚍涸倰岁 1 objectName["propertyName"] " # 暟⟝0CKFDU
1 objectName.propertyName 《ⴀ㿂䚍涸倰岁 1 objectName["propertyName"] " # LFZ⺫わ瑠涯꒳鸮㶶贫䧴僽⟃侸㶶걧瘞〫腋欽鸏珏《岁 ⹛䢀㹒デ㥶瘞䖊⢪欽罏鱒Ⰵ欽鸏珏《岁湱㼩鯱㸞 暟⟝0CKFDU
ⴅ䒭'VODUJPOWT倰岁.FUIPE ⴅ䒭〳⟃㖈暟⟝⟃㢫涸⟤ざ㖒倰鄄㹒デ 䧮⦛〳⟃湬䱺ㄎ〭㸐 蕰ⴅ䒭㖈暟⟝酭鄄㹒デ㸐㽠隶䧭倰岁 倰岁䗳갭鷴麕㸐䨾㿂倴涸暟⟝⢵ㄎ〭
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(); //呼叫⽅方法 ⴅ䒭'VODUJPOWT倰岁.FUIPE
⡹涮植✫㌨ arrayName.sort(), Math.random() 鿪僽㖈ㄎ〭倰岁罜"SSBZ .BUI劥魨㽠僽 䊺竤鄄㹁纏㥪剤䖎㢵㿂䚍莅倰岁涸暟⟝ ⴅ䒭'VODUJPOWT倰岁.FUIPE
㣐鿈⟨涸玑䒭铃鎊鿪갸⯓㹁纏✫♧❉ 呍䗱暟⟝4UBOEBSECVJMUJOPCKFDUT ⢿㥶.BUI 0CKFDU "SSBZ⟃⿻4USJOH 㸐⦛剤ぐ荈涸㿂䚍莅倰岁雊⢪欽罏〳⟃䘰鸠《欽 鸏⛳僽捀➊랃䧮⦛銴鼚⯝⢪欽⥃殆㶶涸⾲㔔 ⴅ䒭'VODUJPOWT倰岁.FUIPE
㼭鑑魨䩛 䒊用♧⦐暟⟝荛㼱銴剤♲⦐㿂䚍 ㄤ♧⦐倰岁 ⢪欽GPS鶬㕖鱒ⴀ鿈须俲 ㄎ〭⡹㹁纏涸倰岁
&/% !〵猰㣐玑䒭鏤鎙灇瑖爢 #Z*SFOF$IBOH