In: Computer Science
I NEED JAVASCRIPT PROGRAM
Chose an activity that you enjoy. It can be a sport that you
watch or participate in, collecting, hobbies, etc. Do
not use a collection of movies since we have covered that in the
assignment. Do not use the same topic as a
friend. (If two students that don’t know each other happen to
select the same topic, that is fine, since they will
naturally have different property names and values.)
1. Select some aspect of the activity and create an array of
objects denoting that aspect. For example, in
the case of movies, you could select movies themselves or you could
select movie stars, producers,
soundtracks, etc. There are many aspects of any activity that you
can use. Feel free to use the web to
research these values.
The array must contain at least 10 objects
The data must be actual data not just gibberish
Each object will have at least 4 properties with values
Each object in the array should have the same set of property names
with different values
At least one string value and one number value
Other properties can be of any JavaScript value type
2. Create a function that can be used to format your object in a
nice string format for output. This function
should be a pure function that takes one object as an argument and
return a string. The string can be
formatted in any way that you feel is appropriate for your data. It
must use one or more properties from
the object in the output string.
3. Create a new array from your array that only contains string
values produced by the above function. Sort
this array alphabetically and display an appropriate heading
followed by this list one string per line.
4. Prompt the user for a numeric value. Display a string (formatted
using the function above) for each of the
objects that have a property (you choose) that are greater or less
(up to you) the value provided by the
user. Be sure to provide a message if there are no objects that
match.
5. Calculate the average value based on some property of your
objects that makes sense. Output it with
descriptive text in a nicely formatted way.
Sample Output:
Movie Titles:
12 Angry Men (1957) by Sidney Lumet
Chak de! India (2007) by Shimit Amin
Hera Pheri (2000) by Priyadarshan
La Haine (1995) by Mathieu Kassovitz
Pulp Fiction (1994) by Quentin Tarantino
Schindler's List (1983) by Steven Spielberg
The Dark Knight (2008) by Christopher Nolan
The Godfather (1972) by Francis Ford Coppola
The Godfather: Part II (1974) by Francis Ford Coppola
The Good, the Bad and the Ugly (1966) by Sergio Leone
The Lord of the Rings: The Fellowship of the Ring (2001) by Peter
Jackson
The Lord of the Rings: The Return of the King (2003) by Peter
Jackson
The Shawshank Redemption (1994) by Frank Darabont
Movies newer than 2005:
Chak de! India (2007) by Shimit Amin
The Dark Knight (2008) by Christopher Nolan
The average age of these movies is: 31 years old.
const data = [
{
title: "The Social Dilemma",
year: 2020,
runtime: 94,
genre: "Science & Nature Docs",
},
{
title: "Miss Americana",
year: 2020,
runtime: 85,
genre: "Music & Concert",
},
{
title: "The Game Changers",
year: 2018,
runtime: 85,
genre: "Lifestyle",
},
{
title: "Three Identical Strangers",
year: 2018,
runtime: 96,
genre: "Real life",
},
{
title: "Human Nature",
year: 2019,
runtime: 94,
genre: "Science & Nature",
},
{
title: "Bending the Arc",
year: 2017,
runtime: 102,
genre: "Social & Cultural",
},
{
title: "Athlete A",
year: 2020,
runtime: 104,
genre: "Social & Cultural",
},
{
title: "Chasing Coral",
year: 2017,
runtime: 89,
genre: "Nature & Ecology",
},
{
title: "Minimalism",
year: 2016,
runtime: 76,
genre: "Nature & Ecology",
},
{
title: "Becoming",
year: 2020,
runtime: 89,
genre: "Social & Cultural",
},
];
// Format the objects into a string
function format(obj) {
var st =
obj.title +
" (" +
obj.year +
") of genre '" +
obj.genre +
"' has runtime " +
obj.runtime +
" minutes.";
return st;
}
//get the average runtime of the Netflix Documentaries
function avgRuntime() {
var l = data.length;
var sum = 0;
for (var i = 0; i < l; i++) {
sum = sum + data[i].runtime;
}
var avg = sum / l;
console.log(
"The average runtime of the documentaries is " + avg + "
minutes"
);
}
//Display documentaries with runtime more than the given
value
function getData(val) {
var l = data.length;
var ctr = 0;
console.log(
"The documentaries with runtime more than " + val + " minutes
are:"
);
for (var i = 0; i < l; i++) {
if (data[i].runtime > val) {
console.log(format(data[i]));
ctr = 1;
}
}
if (ctr === 0) {
console.log("No such documentary found!");
}
}
var l = data.length;
var str = [];
for (var i = 0; i < l; i++) {
var st = format(data[i]);
str.push(st);
}
str.sort();
console.log("The list of top Netflix Documentaries are: ");
for (var i = 0; i < str.length; i++) {
console.log(str[i]);
}
//Prompt user for a value and display results
var val = prompt("Please enter runtime in minutes", 0);
getData(Number(val));
//Get average runtime
avgRuntime();
OUTPUT:
NOTE: