SlideShare a Scribd company logo
1 of 19
Download to read offline
Arrays
Lesson 20
In this Lesson
What is an Array?
In This Lesson
Using for Statement in Arrays
What is an Array?
What is an Array?
An array contains a set of data
represented by a single variable name.
Formats in Creating an Array
• array_name = newArray(number of elements);
Example: quiz = newArray(4);
Formats in Creating an Array
•array_name = newArray(elements);
Example: grades = newArray(85, 83, 90, 89);
Referring to a specific element:
Example:
quiz[0]
quiz[1]
quiz[2]
quiz[3]
Accessing Array
Assigning values to the elements:
Example:
grades[0] = 90;
grades[l] = 83;
grades[2] = 85;
grades[3] = 92;
Accessing Array
Code: sample21.html
<html>
<head><title> Using Arrays </title></head>
<body>
<script language="JavaScript">
nday = new Array(7);
nday[0] = prompt(“Enter the first day of the
week”,””);
nday[1] = prompt(“Enter the second day of the
week”,””);
nday[2] = prompt(“Enter the third day of the
week”,””);
nday[3] = prompt(“Enter the fourth day of the
week”,””);
nday[4] = prompt(“Enter the fith day of the
week”,””);
nday[5] = prompt(“Enter the sixth day of the
week”,””);
nday[6] = prompt(“Enter the seventh day of the
week”,””);
document.writeln(“The first day of the week is “ +
nday[0]);
document.writeln(“<br>”);
document.writeln(“The last day of the week is “ +
nday[6]);
</script>
</body>
</html>
Output: sample21.html
Using for Statement in Arrays
Code: sample22.html
<html>
<head><title>Using Arrays</title></head>
<body>
<script language="JavaScript">
grade = new Array(4);
sum=0;
for(i=0; i<4; i++){
grade[i] = prompt("Enter the grade","");
sum+=parseInt(grade[i]);
}
average = sum/4;
document.writeln("List of grades: <br>");
for(i=0; i<4; i++){
document.writeln("Quarter " + (i+1) + ": ");
document.writeln(grade[i] + "<br>");
}
document.writeln("Average :" + average);
</script>
</body>
</html>
Output: sample22.html
Answer the activity
on page 102.
Test Your Knowledge
Do the activity on
page 103.
Activity Time
Filename: activity15.html
Filename: activity15a.html

More Related Content

Similar to JAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYS

Similar to JAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYS (20)

ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
array Details
array Detailsarray Details
array Details
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays in java.pptx
Arrays in java.pptxArrays in java.pptx
Arrays in java.pptx
 
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppttutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
 
Array
ArrayArray
Array
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
 
Building Java Programas
Building Java ProgramasBuilding Java Programas
Building Java Programas
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 
Javascript Arrays related powerpoint slide set
Javascript Arrays related powerpoint slide setJavascript Arrays related powerpoint slide set
Javascript Arrays related powerpoint slide set
 
Arrays
ArraysArrays
Arrays
 
12. arrays
12. arrays12. arrays
12. arrays
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
 
Chapter 6 Absolute Java
Chapter 6 Absolute JavaChapter 6 Absolute Java
Chapter 6 Absolute Java
 
Chap6java5th
Chap6java5thChap6java5th
Chap6java5th
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Eo gaddis java_chapter_07_5e
Eo gaddis java_chapter_07_5eEo gaddis java_chapter_07_5e
Eo gaddis java_chapter_07_5e
 
Array andfunction
Array andfunctionArray andfunction
Array andfunction
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 

More from ElijahSantos4

LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2ElijahSantos4
 
LP4E-U06L01 Presentation - POWERPOINT PRESENTATION
LP4E-U06L01 Presentation -  POWERPOINT PRESENTATIONLP4E-U06L01 Presentation -  POWERPOINT PRESENTATION
LP4E-U06L01 Presentation - POWERPOINT PRESENTATIONElijahSantos4
 
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINTLESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINTElijahSantos4
 
Introduction to Webpage creation and HTML
Introduction to Webpage creation and HTMLIntroduction to Webpage creation and HTML
Introduction to Webpage creation and HTMLElijahSantos4
 
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARYCHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARYElijahSantos4
 
SONGWRITING LESSON - HOW TO WRITE A SONG
SONGWRITING LESSON - HOW TO WRITE A SONGSONGWRITING LESSON - HOW TO WRITE A SONG
SONGWRITING LESSON - HOW TO WRITE A SONGElijahSantos4
 
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMSFORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMSElijahSantos4
 
Drug Abuse Education - PPT about drugs and solution
Drug Abuse Education - PPT about drugs and solutionDrug Abuse Education - PPT about drugs and solution
Drug Abuse Education - PPT about drugs and solutionElijahSantos4
 
Pyhton dictionary.pdf
Pyhton dictionary.pdfPyhton dictionary.pdf
Pyhton dictionary.pdfElijahSantos4
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxElijahSantos4
 
May-30-2021-a.m.-worship.pptx
May-30-2021-a.m.-worship.pptxMay-30-2021-a.m.-worship.pptx
May-30-2021-a.m.-worship.pptxElijahSantos4
 

More from ElijahSantos4 (13)

LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
 
LP4E-U06L01 Presentation - POWERPOINT PRESENTATION
LP4E-U06L01 Presentation -  POWERPOINT PRESENTATIONLP4E-U06L01 Presentation -  POWERPOINT PRESENTATION
LP4E-U06L01 Presentation - POWERPOINT PRESENTATION
 
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINTLESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
 
Introduction to Webpage creation and HTML
Introduction to Webpage creation and HTMLIntroduction to Webpage creation and HTML
Introduction to Webpage creation and HTML
 
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARYCHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
 
SONGWRITING LESSON - HOW TO WRITE A SONG
SONGWRITING LESSON - HOW TO WRITE A SONGSONGWRITING LESSON - HOW TO WRITE A SONG
SONGWRITING LESSON - HOW TO WRITE A SONG
 
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMSFORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
 
Drug Abuse Education - PPT about drugs and solution
Drug Abuse Education - PPT about drugs and solutionDrug Abuse Education - PPT about drugs and solution
Drug Abuse Education - PPT about drugs and solution
 
DC-CH01Intro.pptx
DC-CH01Intro.pptxDC-CH01Intro.pptx
DC-CH01Intro.pptx
 
FACT OR BLUFF.pptx
FACT OR BLUFF.pptxFACT OR BLUFF.pptx
FACT OR BLUFF.pptx
 
Pyhton dictionary.pdf
Pyhton dictionary.pdfPyhton dictionary.pdf
Pyhton dictionary.pdf
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
 
May-30-2021-a.m.-worship.pptx
May-30-2021-a.m.-worship.pptxMay-30-2021-a.m.-worship.pptx
May-30-2021-a.m.-worship.pptx
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
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...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 

JAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYS