Implement the following user story:
It’s done when the names of five classmates are stored in a single variable named students
.
It’s done when the total number of elements in the students
array is logged to the console.
It’s done when, using a for
loop, the greeting “Great to see you, CLASSMATE_NAME!” logs to the console for each classmate’s name in the students
array.
How can you access each element using the element’s index and the array name?
If you have completed this activity, work through the following challenge to further your knowledge:
while
loop?Use Google or another search engine to research this.
// Creates an array containing names of five student in the class
var students = ["Sarah", "Orlando", "Heather", "Ismael", "Hung"];
// Logs length of the array
console.log(students.length);
// For loop starts at 0, runs while i is less than length of student array
// Increments by 1
for(var i=0; i < students.length; i++) {
// This statement will run each time the loop is executed
console.log("Great to see you, " + students[i] + "!");
}