Question: Follow the instructions to complete each TASK below in JAVASCRIPT (in order). Do everything in the same file. TASK: Using arrow notation, write a function
Follow the instructions to complete each TASK below in JAVASCRIPT (in order). Do everything in the same file.
TASK: Using arrow notation, write a function called poundstokg that will convert from pounds to a kilogram. The function takes an argument (a value in pounds) and returns a value (the argument value converted to kilograms).
TASK: Using arrow notation, write a function called inchestometerst hat will convert from inches to meters. The function takes an argument (a value in inches) and returns a value (the argument value converted to meters).
The following is an array of person objects, each representing a person (name, weight in pounds, and height in inches).
let people = [ {name: "Amy", pounds_weight: 152, inches_height: 63}, {name: "Joe", pounds_weight: 120, inches_height: 64}, {name: "Tom", pounds_weight: 210, inches_height: 78}, {name: "Jim", pounds_weight: 180, inches_height: 68}, {name: "Jen", pounds_weight: 120, inches_height: 62}, {name: "Ann", pounds_weight: 252, inches_height: 63}, {name: "Ben", pounds_weight: 240, inches_height: 72},
];
TASK:Copy the peoplearray into your program.
TASK: Write a function called addbmi that will take a personobject as an argument and it will:
a) calculate his/her bmi (equation below);
b) add a BMI attribute to the person object (with his/her calculated BMI as value);
c) return the (changed) person object.
You should make use of your poundstokg and inchestometers functions. The following equation can be used to calculate the BMI of a person:
BMI = (weight in kg) / (height in meters)2
You could test your addbmi function with any of the items in the array. For example, if you try:
console.log(addbmi(people[0]));
you should see the following result. Notice how the BMI attribute has been added to the object:
At this point you should be able to use map to apply the addbmi function to each person in the array. For testing purposes, try the following instructions:
people.map (addbmi);
console.log(people);
You should see the results below. Notice how each person object now has a bmi attribute:
NOTE: After getting the correct result, make sure you remove the two instructions from your program.
A person is considered overweight if her/his BMI is 25.0 to <30. TASK: Write a function called isOverweightthat will take a person object as an argument and it will return true if the person is overweight and false otherwise. Assume that the person object has the bmi attribute already.
You can test your function using:
console.log(isOverweight(people[0]));
which should display true.
A person is considered obese if her/his BMI is 30 or above. TASK: Write a function called isObesethat will take a person object as an argument and it will return true if the person is obese and false otherwise. Assume that the person object has the BMI attribute already.
You can test your function using:
console.log(isObese(people[0]));
which should display false.
TASK: Use the addbmi andisOverweight functions to chain the map and filter functions on the people array to obtain an array of overweight people. Assign the results to a variable calledoverweight_people. Display the value of the variable to screen. You should see the following:
TASK: Use the addbmi andisObese functions to chain the map and filter functions on the people array to obtain an array of obese people. Assign the results to a variable calledobese_people. Display the value of the variable to screen. You should see the following:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
