Extensive Student Data - Sana-Mohammad-Rafiq25/js-Array-Object-task GitHub Wiki
Give this array of students.
let students = [
{
name: "Amna",
gender: "f",
dob: new Date("02-04-1990"),
address: {
ilaqa: "Gulistan-e-Johar",
city: "Karachi",
country: "Pakistan",
postalCode: 47114
},
phoneNo: "0331-2324243",
admissionTestScore: 56,
hasInternet: true,
hasComputer: false,
hasJob: true,
hasSchoolBefore: false
},
{
name: "Hadia",
gender: "f",
dob: new Date("05-15-1984"),
address: {
ilaqa: "Lyari",
city: "Karachi",
country: "Pakistan",
postalCode: 75660
},
phoneNo: "0345-3452953",
admissionTestScore: 48,
hasInternet: false,
hasComputer: false,
hasJob: false,
hasSchoolBefore: true
},
{
name: "Ahmed",
gender: "m",
dob: new Date("06-27-2002"),
address: {
ilaqa: "University Road",
city: "Quetta",
country: "Pakistan",
postalCode: 82215
},
phoneNo: "0333-0124325",
admissionTestScore: 33,
hasInternet: true,
hasComputer: false,
hasJob: false,
hasSchoolBefore: false
},
{
name: "Fariha",
gender: "f",
dob: new Date("09-13-1998"),
address: {
ilaqa: "University Road",
city: "Karachi",
country: "Pakistan",
postalCode: 82215
},
phoneNo: "0331-9432532",
admissionTestScore: 33,
hasInternet: true,
hasComputer: false,
hasJob: false,
hasSchoolBefore: false
},
{
name: "Abdullah",
gender: "m",
dob: new Date("01-24-1972"),
address: {
ilaqa: "Bazar Colony",
city: "Lahore",
country: "Pakistan",
postalCode: 32212
},
phoneNo: "0345-9912121",
admissionTestScore: 33,
hasInternet: false,
hasComputer: false,
hasJob: true,
hasSchoolBefore: true
}
];
Q1.
Solution:-
for (i = 0; i < students.length; i++) {
console.log('Name:' + ' ' + students[i].name)
console.log('Gender:' + ' ' + students[i].gender)
console.log('City:' + ' ' + students[i].address.city)
console.log('Score:' + ' ' + students[i].admissionTestScore + ' ' + 'marks')
console.log(' ');
}
Q2. Print names of female students only.
Solution:-
const genderIsFemale = gender => gender === "f"
const Female = students.filter(item => genderIsFemale(item.gender))
console.log(Female)
Q3. Print names of male students only.
Solution:-
const genderIsMale = gender => gender === "m"
const Male = students.filter(item => genderIsMale(item.gender))
console.log(Male)
Q4. Print names of students who have passed the admission test. Passing marks are 50.
Solution:-
Q6. Print address of each student in this format:
Amna's address:
Gulistan-e-Johar in Karachi, Pakistan
Solution:-
for (i = 0; i < students.length; i++) {
console.log(students[i].name + " 's address")
console.log(students[i].address.ilaqa + ' ' + 'in' + ' ' + students[i].address.city + ', ' + students[i].address.country)
}