1. Let's make some classroomsmandatoryImport the ClassRoom class from 0-classroom.js.Implement a function named initializeRooms. It should return an array of 3 ClassRoom objects with the sizes 19, 20, and 34 (in this order).bob@dylan:~$ cat 1-main.jsimport initializeRooms from './1-make_classrooms.js';console.log(initializeRooms());bob@dylan:~$ bob@dylan:~$ npm run dev 1-main.js [ ClassRoom { _maxStudentsSize: 19 }, ClassRoom { _maxStudentsSize: 20 }, ClassRoom { _maxStudentsSize: 34 }]bob@dylan:~$
Question
- Let's make some classroomsmandatoryImport the ClassRoom class from 0-classroom.js.Implement a function named initializeRooms. It should return an array of 3 ClassRoom objects with the sizes 19, 20, and 34 (in this order).bob@dylan:~ bob@dylan:~
Solution
Primero, asegúrate de tener la clase ClassRoom en un archivo llamado 0-classroom.js. Aquí hay un ejemplo de cómo podría verse esa clase:
// 0-classroom.js
export default class ClassRoom {
constructor(maxStudentsSize) {
this._maxStudentsSize = maxStudentsSize;
}
}
Luego, crea una función initializeRooms en un archivo llamado 1-make_classrooms.js que importe la clase ClassRoom y devuelva un array de tres objetos ClassRoom con los tamaños especificados:
// 1-make_classrooms.js
import ClassRoom from './0-classroom.js';
function initializeRooms() {
const room1 = new ClassRoom(19);
const room2 = new ClassRoom(20);
const room3 = new ClassRoom(34);
return [room1, room2, room3];
}
export default initializeRooms;
Finalmente, en tu archivo 1-main.js, importa y usa la función initializeRooms para verificar que todo funcione correctamente:
// 1-main.js
import initializeRooms from './1-make_classrooms.js';
console.log(initializeRooms());
Cuando ejecutes el archivo 1-main.js con el comando npm run dev 1-main.js, deberías obtener la salida esperada:
[
ClassRoom { _maxStudentsSize: 19 },
ClassRoom { _maxStudentsSize: 20 },
ClassRoom { _maxStudentsSize: 34 }
]
Similar Questions
0. You used to attend a place like this at some pointmandatoryImplement a class named ClassRoom:Prototype: export default class ClassRoomIt should accept one attribute named maxStudentsSize (Number) and assigned to _maxStudentsSizebob@dylan:~$ cat 0-main.jsimport ClassRoom from "./0-classroom.js";const room = new ClassRoom(10);console.log(room._maxStudentsSize)bob@dylan:~$ bob@dylan:~$ npm run dev 0-main.js 10bob@dylan:~$
2. A Course, Getters, and SettersmandatoryImplement a class named HolbertonCourse:Constructor attributes:name (String)length (Number)students (array of Strings)Make sure to verify the type of attributes during object creationEach attribute must be stored in an “underscore” attribute version (ex: name is stored in _name)Implement a getter and setter for each attribute.bob@dylan:~$ cat 2-main.jsimport HolbertonCourse from "./2-hbtn_course.js";const c1 = new HolbertonCourse("ES6", 1, ["Bob", "Jane"])console.log(c1.name);c1.name = "Python 101";console.log(c1);try { c1.name = 12;} catch(err) { console.log(err);}try { const c2 = new HolbertonCourse("ES6", "1", ["Bob", "Jane"]);}catch(err) { console.log(err);}bob@dylan:~$ bob@dylan:~$ npm run dev 2-main.js ES6HolbertonCourse { _name: 'Python 101', _length: 1, _students: [ 'Bob', 'Jane' ]}TypeError: Name must be a string ...TypeError: Length must be a number ...bob@dylan:~$
Create a function named getListStudents that returns an array of objects.Each object should have three attributes: id (Number), firstName (String), and location (String).The array contains the following students in order:Guillaume, id: 1, in San FranciscoJames, id: 2, in ColumbiaSerena, id: 5, in San Franciscobob@dylan:~$ cat 0-main.jsimport getListStudents from "./0-get_list_students.js";console.log(getListStudents());bob@dylan:~$ bob@dylan:~$ npm run dev 0-main.js [ { id: 1, firstName: 'Guillaume', location: 'San Francisco' }, { id: 2, firstName: 'James', location: 'Columbia' }, { id: 5, firstName: 'Serena', location: 'San Francisco' }]bob@dylan:~$
Create a function getListStudentIds that returns an array of ids from a list of object.This function is taking one argument which is an array of objects - and this array is the same format as getListStudents from the previous task.If the argument is not an array, the function is returning an empty array.You must use the map function on the array.bob@dylan:~$ cat 1-main.jsimport getListStudentIds from "./1-get_list_student_ids.js";import getListStudents from "./0-get_list_students.js";console.log(getListStudentIds("hello"));console.log(getListStudentIds(getListStudents()));bob@dylan:~$ bob@dylan:~$ npm run dev 1-main.js [][ 1, 2, 5 ]bob@dylan:~$
Create a function getStudentsByLocation that returns an array of objects who are located in a specific city.It should accept a list of students (from getListStudents) and a city (string) as parameters.You must use the filter function on the array.bob@dylan:~$ cat 2-main.jsimport getListStudents from "./0-get_list_students.js";import getStudentsByLocation from "./2-get_students_by_loc.js";const students = getListStudents();console.log(getStudentsByLocation(students, 'San Francisco'));bob@dylan:~$ bob@dylan:~$ npm run dev 2-main.js [ { id: 1, firstName: 'Guillaume', location: 'San Francisco' }, { id: 5, firstName: 'Serena', location: 'San Francisco' }]bob@dylan:~$
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.