On the final exam I will ask two types of questions: traditional JavaScript and React. The traditional JavaScript questions will be similar to the questions I asked on the second midterm. Below you will find sample questions that are similar in style and difficulty to the questions I will ask on the final.
All of the questions below concern an application that contains a people
state variable that stores an array of objects. Each object represents a person and has a name property and an age property.
1. Write the code for a PersonMaker
component. This component consists of two text input fields where the user can input the name and age for a person and an 'Add Person' button that they can click to create a new Person object. Your PersonMaker
component should have a single prop, addPerson
, which receives a function that takes a single person object as its parameter.
2. Write the code for a PeopleTable
component. This component displays a table of people with columns for each person's name and age. This component should have two props: a people
prop that receives a list of objects representing people and a minAge
prop that receives a minimum age value. Only people whose age is greater than or equal to the value of minAge
should be displayed in the table.
3. Write the code for an App component that maintains an array people
of objects representing people as one of its state variables. The component should also include an ageLimit
state variable, along with a text input field and a 'Set Age Limit' button that the user can use to update the age limit. The App component will display a PeopleTable and a PersonMaker.