SlideShare a Scribd company logo
1 of 18
JavaScript – Class 3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
String Object – comparing strings var  answer = “xyz”; stringName. toLowerCase() ; stringName. toUpperCase() ;
String Object var  answer =  prompt("What breed of dog was Lassie?", "");  if (answer == "collie")  {  document.write("Yes, that is correct!");  }
var  answer =  prompt("What breed of dog was Lassie?", ""); if (answer. toLowerCase()  == "collie")  {  document.write("Yes, Lassie was a collie!");  }  else  {  document.write("No, you are wrong!");  }  comparison
Switch Statement For checking a condition when there are a large number of possibilities  Can be used in place of an if else if What it contains: •  the  test statement  - the expression/condition to test  •  the  case statements  - the possible answers •  the  break statements  – stops checking after a match is •  the  default statement  –executes if none of the possible answers are found
var  theDay=  prompt("What day is the fourth of July?", ""); switch  ( theDay.toLowerCase())  -> the test expression– what we are comparing {   case  “monday”: execute some code;  break;  case  “tuesday” :  execute some code;  break;  default:  -> - the default statement - if nothing matches, this will execute  execute some code;  break;  } See pages 4-6 handout and sample code files Double quotes for a literal/string
the Array Object  – (chapter 2)  •  Similar to a variable except that it can hold more than one item of data at a time  •  Each piece of data stored is referred to as an  element  •  Each element is referenced by a number or an  index  •  The index number is enclosed in brackets –  [ ]  •  Arrays start with the number  0   •  Arrays have a  length property , which is the number of elements in the array  •  Arrays are defined with the JavaScript key word “ new ”  •  The length of the array minus 1 gives the number of the  last index
Declaring an Array var  myArray = new Array()  or   var  myArray = new Array(4) We are creating a “ new ”  instance  of the “ Array() ” object  keyword keyword Array object – upper case “A”
Listing the  elements  in an array var dogs = new Array();  dogs[0] = &quot;Missy&quot; ;  dogs[1] = &quot;Letty&quot; ;  dogs[2] = &quot;Andy&quot; ;  dogs[3] = &quot;Terri&quot; ;  var dogs = new Array(“Missy”, “Letty”, “Andy”, “Terri”); ______________________________________________ Returning the  value  of the array  elements : document.write(&quot;my first dog is &quot; + dogs[0] + &quot;<br>&quot;);  document.write(&quot;my second dog is &quot; + dogs[1] + &quot;<br>&quot;);  see page 8 index position 0
Loops   A loop is a type of JavaScript statement that repeats a block of code over and over again if a condition evaluates to true  Two kinds of loops -– a “ for ” loop and a “ while ” loop  •  Use the “ for ” loop  when you  know , or can determine by a calculation,  the number of times  you want to repeat the code  •  Use the “ while ” loop  when you  do not know how many times  you will need to repeat the block of code
The “for” loop – Commonly used with an array  •  Repeats a block of code for a certain number of times  •  When you know or can determine how many times to repeat the code  •  Involves some kind of  counter  that is  incremented  as long as the condition is true
The “for in” loop –  ONLY  used with an array  •  Repeats a block of code for a certain number of times  •  When you know or can determine how many times to repeat the code  •  Involves some kind of  counter  that is  incremented  as long as the condition is true var elementIndex;  var myArray();  for (elementIndex  in  myArray)  {  document.write(myArray[elementIndex] + “<br>”);  }
for loop - Pages 9 -11
for in loop - Page 12
for in loop - Page 12
while loop  •  Allows you to test a condition and keep on looping as long as the condition is    true;  will stop when the condition is false  •  If the condition is false to begin with, it will never loop  •  Used when you don’t know the number of times you need to loop  •  You must increment the counter in the code to execute or it will loop  indefinitely and the computer will crash ☺  var counter;  counter = prompt(&quot;Enter a number from 1 to 10&quot;, &quot;&quot;);  while (counter <= 10)  {  document.write(&quot;this is count number &quot; + counter + &quot;<br><br>&quot; );  counter++  }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot (20)

Regex cheatsheet part-1
Regex cheatsheet part-1Regex cheatsheet part-1
Regex cheatsheet part-1
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Javascript - Break statement, type conversion, regular expression
Javascript - Break statement, type conversion, regular expressionJavascript - Break statement, type conversion, regular expression
Javascript - Break statement, type conversion, regular expression
 
Introduction to php 5
Introduction to php   5Introduction to php   5
Introduction to php 5
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
Javascript - Tutorial
Javascript - TutorialJavascript - Tutorial
Javascript - Tutorial
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Lesson 4 constant
Lesson 4  constantLesson 4  constant
Lesson 4 constant
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Effective PHP. Part 6
Effective PHP. Part 6Effective PHP. Part 6
Effective PHP. Part 6
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Lesson 3 php numbers
Lesson 3  php numbersLesson 3  php numbers
Lesson 3 php numbers
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-Sharp
 
Bsit1
Bsit1Bsit1
Bsit1
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 

Viewers also liked

The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...
The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...
The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...William Kritsonis
 
Dr. William Allan Kritsonis - Expression & Associational Rights PPT.
Dr. William Allan Kritsonis - Expression & Associational Rights PPT.Dr. William Allan Kritsonis - Expression & Associational Rights PPT.
Dr. William Allan Kritsonis - Expression & Associational Rights PPT.William Kritsonis
 
NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...
NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...
NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...William Kritsonis
 
ADMN 5053 Special Programs - Dr. W.A. Kritsonis
ADMN 5053 Special Programs - Dr. W.A. KritsonisADMN 5053 Special Programs - Dr. W.A. Kritsonis
ADMN 5053 Special Programs - Dr. W.A. KritsonisWilliam Kritsonis
 
Ch 15 Legalities Affecting Schooling - Dr. William Allan Kritsonis
Ch 15 Legalities Affecting Schooling - Dr. William Allan KritsonisCh 15 Legalities Affecting Schooling - Dr. William Allan Kritsonis
Ch 15 Legalities Affecting Schooling - Dr. William Allan KritsonisWilliam Kritsonis
 
Selem image and_phantoms
Selem image and_phantomsSelem image and_phantoms
Selem image and_phantomsJonathan Swales
 
Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...
Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...
Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...William Kritsonis
 
Samanthas geothermal powerpoint
Samanthas geothermal powerpointSamanthas geothermal powerpoint
Samanthas geothermal powerpointroom112008
 
Graphic Novels Intro # 2
Graphic Novels Intro # 2Graphic Novels Intro # 2
Graphic Novels Intro # 2bradythecamel
 
Witness, Worldview And The Workplace
Witness, Worldview And The WorkplaceWitness, Worldview And The Workplace
Witness, Worldview And The WorkplaceJonathan Swales
 
Presentation
PresentationPresentation
PresentationSallyL
 
How Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 MigrationHow Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 MigrationShaun McDonald
 
Viz Transcript2min X
Viz Transcript2min XViz Transcript2min X
Viz Transcript2min Xwatchthefly
 
Cluster coordinators training programme
Cluster coordinators training programmeCluster coordinators training programme
Cluster coordinators training programmeKirti Shivakumar
 

Viewers also liked (20)

Famous artists
Famous artistsFamous artists
Famous artists
 
tradizii
tradiziitradizii
tradizii
 
The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...
The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...
The Design of an Undergraduate Program in Homeland Security - Jon E. Travis a...
 
Dr. William Allan Kritsonis - Expression & Associational Rights PPT.
Dr. William Allan Kritsonis - Expression & Associational Rights PPT.Dr. William Allan Kritsonis - Expression & Associational Rights PPT.
Dr. William Allan Kritsonis - Expression & Associational Rights PPT.
 
NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...
NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...
NATIONAL FORUM JOURNALS - A Group of National Refereed Journals on the Leadin...
 
ADMN 5053 Special Programs - Dr. W.A. Kritsonis
ADMN 5053 Special Programs - Dr. W.A. KritsonisADMN 5053 Special Programs - Dr. W.A. Kritsonis
ADMN 5053 Special Programs - Dr. W.A. Kritsonis
 
Ch 15 Legalities Affecting Schooling - Dr. William Allan Kritsonis
Ch 15 Legalities Affecting Schooling - Dr. William Allan KritsonisCh 15 Legalities Affecting Schooling - Dr. William Allan Kritsonis
Ch 15 Legalities Affecting Schooling - Dr. William Allan Kritsonis
 
Selem image and_phantoms
Selem image and_phantomsSelem image and_phantoms
Selem image and_phantoms
 
Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...
Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...
Dr. Jennifer T. Butcher & Dr. William Allan Kritsonis - Article: A National P...
 
Samanthas geothermal powerpoint
Samanthas geothermal powerpointSamanthas geothermal powerpoint
Samanthas geothermal powerpoint
 
Graphic Novels Intro # 2
Graphic Novels Intro # 2Graphic Novels Intro # 2
Graphic Novels Intro # 2
 
Court Case 5
Court  Case 5Court  Case 5
Court Case 5
 
Witness, Worldview And The Workplace
Witness, Worldview And The WorkplaceWitness, Worldview And The Workplace
Witness, Worldview And The Workplace
 
Presentation
PresentationPresentation
Presentation
 
Court Case 2
Court Case 2Court Case 2
Court Case 2
 
Court Case Employment
Court Case  EmploymentCourt Case  Employment
Court Case Employment
 
How Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 MigrationHow Testing Helped The API 0.6 Migration
How Testing Helped The API 0.6 Migration
 
Viz Transcript2min X
Viz Transcript2min XViz Transcript2min X
Viz Transcript2min X
 
Ukazka Predvadeni
Ukazka PredvadeniUkazka Predvadeni
Ukazka Predvadeni
 
Cluster coordinators training programme
Cluster coordinators training programmeCluster coordinators training programme
Cluster coordinators training programme
 

Similar to CSIS 138 JavaScript Class3

Php Loop
Php LoopPhp Loop
Php Looplotlot
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, loopingMuthuganesh S
 
JavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentationJavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentationM Sajid R
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9Vince Vo
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basicsrobertbenard
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basicsrobertbenard
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and StringsEduardo Bergavera
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameAntony Stubbs
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
 

Similar to CSIS 138 JavaScript Class3 (20)

Php Loop
Php LoopPhp Loop
Php Loop
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Introducing Swift v2.1
Introducing Swift v2.1Introducing Swift v2.1
Introducing Swift v2.1
 
CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
 
JavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentationJavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScript / Web Engineering / Web Development / html + css + js/presentation
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

CSIS 138 JavaScript Class3

  • 1.
  • 2. String Object – comparing strings var answer = “xyz”; stringName. toLowerCase() ; stringName. toUpperCase() ;
  • 3. String Object var answer = prompt(&quot;What breed of dog was Lassie?&quot;, &quot;&quot;); if (answer == &quot;collie&quot;) { document.write(&quot;Yes, that is correct!&quot;); }
  • 4. var answer = prompt(&quot;What breed of dog was Lassie?&quot;, &quot;&quot;); if (answer. toLowerCase() == &quot;collie&quot;) { document.write(&quot;Yes, Lassie was a collie!&quot;); } else { document.write(&quot;No, you are wrong!&quot;); } comparison
  • 5. Switch Statement For checking a condition when there are a large number of possibilities Can be used in place of an if else if What it contains: • the test statement - the expression/condition to test • the case statements - the possible answers • the break statements – stops checking after a match is • the default statement –executes if none of the possible answers are found
  • 6. var theDay= prompt(&quot;What day is the fourth of July?&quot;, &quot;&quot;); switch ( theDay.toLowerCase()) -> the test expression– what we are comparing { case “monday”: execute some code; break; case “tuesday” : execute some code; break; default: -> - the default statement - if nothing matches, this will execute execute some code; break; } See pages 4-6 handout and sample code files Double quotes for a literal/string
  • 7. the Array Object – (chapter 2) • Similar to a variable except that it can hold more than one item of data at a time • Each piece of data stored is referred to as an element • Each element is referenced by a number or an index • The index number is enclosed in brackets – [ ] • Arrays start with the number 0 • Arrays have a length property , which is the number of elements in the array • Arrays are defined with the JavaScript key word “ new ” • The length of the array minus 1 gives the number of the last index
  • 8. Declaring an Array var myArray = new Array() or var myArray = new Array(4) We are creating a “ new ” instance of the “ Array() ” object keyword keyword Array object – upper case “A”
  • 9. Listing the elements in an array var dogs = new Array(); dogs[0] = &quot;Missy&quot; ; dogs[1] = &quot;Letty&quot; ; dogs[2] = &quot;Andy&quot; ; dogs[3] = &quot;Terri&quot; ; var dogs = new Array(“Missy”, “Letty”, “Andy”, “Terri”); ______________________________________________ Returning the value of the array elements : document.write(&quot;my first dog is &quot; + dogs[0] + &quot;<br>&quot;); document.write(&quot;my second dog is &quot; + dogs[1] + &quot;<br>&quot;); see page 8 index position 0
  • 10. Loops A loop is a type of JavaScript statement that repeats a block of code over and over again if a condition evaluates to true Two kinds of loops -– a “ for ” loop and a “ while ” loop • Use the “ for ” loop when you know , or can determine by a calculation, the number of times you want to repeat the code • Use the “ while ” loop when you do not know how many times you will need to repeat the block of code
  • 11. The “for” loop – Commonly used with an array • Repeats a block of code for a certain number of times • When you know or can determine how many times to repeat the code • Involves some kind of counter that is incremented as long as the condition is true
  • 12. The “for in” loop – ONLY used with an array • Repeats a block of code for a certain number of times • When you know or can determine how many times to repeat the code • Involves some kind of counter that is incremented as long as the condition is true var elementIndex; var myArray(); for (elementIndex in myArray) { document.write(myArray[elementIndex] + “<br>”); }
  • 13. for loop - Pages 9 -11
  • 14. for in loop - Page 12
  • 15. for in loop - Page 12
  • 16. while loop • Allows you to test a condition and keep on looping as long as the condition is true; will stop when the condition is false • If the condition is false to begin with, it will never loop • Used when you don’t know the number of times you need to loop • You must increment the counter in the code to execute or it will loop indefinitely and the computer will crash ☺ var counter; counter = prompt(&quot;Enter a number from 1 to 10&quot;, &quot;&quot;); while (counter <= 10) { document.write(&quot;this is count number &quot; + counter + &quot;<br><br>&quot; ); counter++ }
  • 17.
  • 18.

Editor's Notes

  1. The JavaScript Language consists of objects CSIS 138 Instructor Teresa Pelkie Class 3 - Summer 2008