dev1 – JS Objects problem set

Create a single HTML / JS pair students.html / students.js which you can download from here (or copy/paste the code from the snippet below). It includes descriptions of the problems and the array of objects needed to write the following functions:

  • CT course count for loop – Create a function ctCourseCount(studArr) that takes the supplied array of objects data structure as a value. When called, use a for loop to print a value for each student and the number of CT courses taken. For example: “Voski Dreher has taken 9 courses in CT.”
  • CT course count forEach – Create a function ctCourseCountforEach(studArr) that takes the supplied array of objects data structure as a value. When called, use a forEach method to print a value for each student and the number of CT courses taken. For example: “Voski Dreher has taken 9 courses in CT.”
  • CT students not enrolled – Create a function isNotEnrolled(studArr) takes the supplied array of objects data structure as a value. When called, the console prints a list of students that are not enrolled. For example, “Wolf Shepard” should be on that list.
  • CT courses taken – Create a function coursesTaken(studArr) that takes the supplied array of objects data structure as a value. When called, the console prints a list of students and every course that student has taken. For example, “Wolf Shepard has taken: CT 101, CT 201, CT 137, CT 160, CT 360”
var students = [{
        name: "Diksha Dohman",
        age: 20,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 210", "CT 137", "CT 205"],
        totalCredits: 75,
        enrolled: true
    },
    {
        name: "Voski Dreher",
        age: 24,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 160", "CT 201", "CT 210", "CT 137", "CT 205", "CT 240", "CT 355", "CT 345"],
        totalCredits: 110,
        enrolled: true
    },
    {
        name: "Divya Glas",
        age: 19,
        major: "Communications Technology",
        coursesTaken: ["CT 101"],
        totalCredits: 15,
        enrolled: false
    },
    {
        name: "Theofanis Sandoval",
        age: 20,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 201", "CT 137", "CT 160", "CT 360", "CT 370", "CT 381", "CT 385"],
        totalCredits: 95,
        enrolled: true
    },
    {
        name: "Wolf Shepard",
        age: 21,
        major: "Communications Technology",
        coursesTaken: ["CT 101", "CT 201", "CT 137", "CT 160", "CT 360"],
        totalCredits: 45,
        enrolled: false
    }
]

//Complete the functions below

//All functions take the above students array of objects as an argument.

//create a ctCourseCount function that console logs the student's name and the number of courses taken.
//use a for loop for this function
//For example: “Voski Dreher has taken 9 courses in CT.”
function ctCourseCount(studarr) {

}

//Create a second version of the function above but use 
//a forEach method instead of a for loop
function ctCourseCountforEach(studarr) {

}

//CT students not enrolled function
//the console prints a list of students that are not enrolled. 
function isNotEnrolled(studarr) {

}

//CT courses taken listed function
//When called, the console prints a list of students and every course that student has taken. 
//For example, “Wolf Shepard has taken: CT 101, CT 201, CT 137, CT 160, CT 360”
function coursesTaken(studarr) {

}

Leave a comment

Your email address will not be published. Required fields are marked *

css.php