FelixTheNewbie
New Coder
Hi there!
I have a newbie question. My task is the following.
There is the array "courses" consisting of a unknown number of arrays with strings that show the students of the course. I want to find out which course in "courses" is the smallest one. My thinking was the following.
The problem is that I always receive the error message: Uncaught ReferenceError: course is not defined at red line
I cannot wrap my head around it. Why should course be undefined since the loop is running all numbers from 0 til the max number of courses?
I have a newbie question. My task is the following.
There is the array "courses" consisting of a unknown number of arrays with strings that show the students of the course. I want to find out which course in "courses" is the smallest one. My thinking was the following.
JavaScript:
// Find out how many courses currently exist
var coursesCount = courses.length
// Compare the number of students of each course with the next one and filter out the smallest one
for (var i = 0; i <= coursesCount; i++){
console.log(courses[I].length)
if (i == 0){
var smallestCourse = courses[I];
}
else {
if (courses[I].length < smallestCourse.length){
smallestCourse = course[I]; //red line (does not show in code block)
}
}
}
// Tell me what members are in the smallest course
console.log(smallestCourse)
The problem is that I always receive the error message: Uncaught ReferenceError: course is not defined at red line
I cannot wrap my head around it. Why should course be undefined since the loop is running all numbers from 0 til the max number of courses?
Last edited by a moderator: