Question

In: Computer Science

I NEED JAVASCRIPT PROGRAM Chose an activity that you enjoy. It can be a sport that...

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.

Solutions

Expert Solution


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:

  1. The above code is written in javascript with 10 data as Netflix documentaries.
  2. The object has 4 properties: title,year,runtime and genre.
  3. Pertaining to question number 4, it is asked that the user is prompted to enter a value, for that we are using a prompt (window prompt), to get value from the user.
  4. To check the working of the above code, I recommend making an html file and enter the above code in a <script> tag. Open the html file in a browser, you will be asked to enter a value (pertaining to question 4). After entering the value, right click the page and choose "Inspect". A sidebar will be opened and click on the tab "Console". Here you can check the output of this code. The screenshot provided also shows the result using a console while inspecting the page.

Related Solutions

I need to design and implement a JAVASCRIPT program that will allow us to determine the...
I need to design and implement a JAVASCRIPT program that will allow us to determine the length of time needed to pay off a credit card balance, as well as the total interest paid. The program must implement the following functions: displayWelcome This function should display the welcome message to the user explaining what the program does. calculateMinimumPayment This function calculates the minimum payment. It should take balance and minimum payment rate as arguments and return the minimum payment. So...
Write an Html Page that uses JavaScript Program to make a Blackjack Game. I need to...
Write an Html Page that uses JavaScript Program to make a Blackjack Game. I need to write an html file (P5.html) that uses JavaScript program to create a Blackjack game. 1. Blackjack Games Rules: a. The object of the game is to "beat the dealer", which can be done in a number of ways: • Get 21 points on your first two cards (called a blackjack), without a dealer blackjack; • Reach a final score higher than the dealer without...
I have this matlab program, and need to turn it into a C++ program. Can anyone...
I have this matlab program, and need to turn it into a C++ program. Can anyone help me with this? % Prompt the user for the values x and y x = input ('Enter the x coefficient: '); y = input ('Enter the y coefficient: '); % Calculate the function f(x,y) based upon % the signs of x and y. if x >= 0    if y >= 0        fun = x + y;    else        fun = x + y^2;    end...
I need a rationale outlining the purpose of why I chose energy drinks
I need a rationale outlining the purpose of why I chose energy drinks
What I need is for you diagnose, Tell me why you chose that diagnosis. Signs, Symptoms,...
What I need is for you diagnose, Tell me why you chose that diagnosis. Signs, Symptoms, Age, lifestyle, any other factors to lead you to your conclusion. Give some diagnostic tests to confirm your Dx. Then a treatment plan. Patient presents no symptoms occurring at visit. Patient states he has started training for a marathon but has to stop due to tightness in chest and coughing. Patient does not know if there is any wheezing as he runs with an...
What I need is for you diagnose, Tell me why you chose that diagnosis. Signs, Symptoms,...
What I need is for you diagnose, Tell me why you chose that diagnosis. Signs, Symptoms, Age, lifestyle, any other factors to lead you to your conclusion. Give some diagnostic tests to confirm your Dx. Then a treatment plan. Patient presents with a sore on his right big toe. Patient states sore has been there for 10 days and is not getting better if anything he thinks it is looking worse and fears infection. Patient also states his leg has...
What I need is for you diagnose, Tell me why you chose that diagnosis. Signs, Symptoms,...
What I need is for you diagnose, Tell me why you chose that diagnosis. Signs, Symptoms, Age, lifestyle, any other factors to lead you to your conclusion. Give some diagnostic tests to confirm your Dx. Then a treatment plan. Case 1 Bella is a 31 year old nervous young lady who came to see me because she and her husband have been trying to get pregnant, but have not been successful. She has been so afraid that she will never...
hello I need a gene that produces an enzyme that can be easily assayed for activity....
hello I need a gene that produces an enzyme that can be easily assayed for activity. please give me at least three choices thanks
I chose the temperature of New Jersey in two different months as below, I need to...
I chose the temperature of New Jersey in two different months as below, I need to calculate mean, median, mode, and range for each group. Find the variance and standard deviation for each group. Find the 95% confidence interval the mean of each group and test the hypothesis that the means are different (.05 significance) January March 1 41 46 2 50 62 3 48 59 4 52 58 5 45 54 6 46 47 7 44 49 8 45...
I chose the temperature of New Jersey in two different months as below, I need to...
I chose the temperature of New Jersey in two different months as below, I need to calculate mean, median, mode, and range for each group. Find the variance and standard deviation for each group. Find the 95% confidence interval the mean of each group and test the hypothesis that the means are different (.05 significance) January March 1 41 46 2 50 62 3 48 59 4 52 58 5 45 54 6 46 47 7 44 49 8 45...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT