- Fork this repo and
git clone
it down to your computer - Create two files
index.html
andscript.js
- Include
script.js
inindex.html
using a<script>
tag - Open
index.html
in your web browser and open the console - After answering each section below,
git commit
your work - When you're finished or when time is up, push your work to your remote repo, and file a Pull Request
Given the following array of horses
:
const horses = [
{
name: 'maythehorsebewithu',
active: true,
country: 'AUS',
yearOfBirth: 2000,
hourlyRate: 30,
numOfHoursWorked: 2000
},
{
name: 'Seabiscuit',
active: true,
country: 'USA',
yearOfBirth: 2007,
hourlyRate: 50,
numOfHoursWorked: 2500
},
{
name: 'Justify',
active: true,
country: 'USA',
yearOfBirth: 2004,
hourlyRate: 30,
numOfHoursWorked: 2000
},
{
name: 'Lost in the Fog',
active: false,
country: 'AUS',
yearOfBirth: 1981,
hourlyRate: 88,
numOfHoursWorked: 900
},
{
name: 'Eclipse',
active: false,
country: 'AUS',
yearOfBirth: 2003,
hourlyRate: 12,
numOfHoursWorked: 9000
},
{
name: 'Citation',
active: true,
country: 'AUS',
yearOfBirth: 2003,
hourlyRate: 42,
numOfHoursWorked: 6450
}
]
Write code to do the following (sometimes it helps to write each solution in a for
loop first):
-
Use
.forEach
to print the name of each horse.Expected output:
maythehorsebewithu Seabiscuit Justify Lost in the Fog Eclipse Citation
-
Use
.map
to return an array of the years of birth for each horse.Expected output:
[2000, 2007, 2004, 1981, 2003, 2003]
-
Use
.filter
to filter in only the active horses.Expected output:
[ {name: 'maythehorsebewithu', active: true, country: 'AUS', yearOfBirth: 2000, hourlyRate: 30, …}, {name: 'Seabiscuit', active: true, country: 'USA', yearOfBirth: 2007, hourlyRate: 50, …}, {name: 'Justify', active: true, country: 'USA', yearOfBirth: 2004, hourlyRate: 30, …}, {name: 'Citation', active: true, country: 'AUS', yearOfBirth: 2003, hourlyRate: 42, …} ]
-
Use the appropriate method(s) to select the horses from Australia.
Expected output:
[ {name: 'maythehorsebewithu', active: true, country: 'AUS', yearOfBirth: 2000, hourlyRate: 30, …}, {name: 'Lost in the Fog', active: false, country: 'AUS', yearOfBirth: 1981, hourlyRate: 88, …}, {name: 'Eclipse', active: false, country: 'AUS', yearOfBirth: 2003, hourlyRate: 12, …}, {name: 'Citation', active: true, country: 'AUS', yearOfBirth: 2003, hourlyRate: 42, …} ]
-
Use the appropriate method(s) to select horses that earn $50 or more per hour.
Expected output:
[ {name: 'Seabiscuit', active: true, country: 'USA', yearOfBirth: 2007, hourlyRate: 50, …}, {name: 'Lost in the Fog', active: false, country: 'AUS', yearOfBirth: 1981, hourlyRate: 88, …} ]
-
Use the appropriate method(s) to get a list of the totals earned by each horse.
Expected output:
[60000, 125000, 60000, 79200, 108000, 270900]
Use the appropriate method to return horses from youngest to oldest hint: look up "JS sort
compare function".
Expected output:
``` text
[
{name: 'Seabiscuit', active: true, country: 'USA', yearOfBirth: 2007, hourlyRate: 50, …},
{name: 'Justify', active: true, country: 'USA', yearOfBirth: 2004, hourlyRate: 30, …},
{name: 'Eclipse', active: false, country: 'AUS', yearOfBirth: 2003, hourlyRate: 12, …},
{name: 'Citation', active: true, country: 'AUS', yearOfBirth: 2003, hourlyRate: 42, …},
{name: 'maythehorsebewithu', active: true, country: 'AUS', yearOfBirth: 2000, hourlyRate: 30, …},
{name: 'Lost in the Fog', active: false, country: 'AUS', yearOfBirth: 1981, hourlyRate: 88, …}
]
```