Question

In: Computer Science

in javascript, Write a method for calculating (and returning) the total length of all songs in...

in javascript, Write a method for calculating (and returning) the total length of all songs in the playlist. Do not use indexes or a for-each loop (those would be perfectly fine ways to solve the problem, but we want to practice another way).

Solutions

Expert Solution

Please upvote if you are able to understand this and if there is any query do mention it in the comment section.

CODE:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <script>

        const playlist = [//assuming the playlist in an array

            "Song 1",

            "Song 2",

            "Song 3",

            "Song 4",

        ]

        let count = 0//variable to count the number of songs

        playlist.map(p => {//map function to loop through the array of songs

            count = count + 1//increasing the count on each song

        })

        //printing the number of songs in the playlist

        document.write(`Number of songs in the playlist: ${count}`)

    </script>

</body>

</html>

OUTPUT:

If this was supposed to be done in any other way or something else is required in this then please mention in the comment section otherwise please upvote.


Related Solutions

In javascript, Write a compareTo method for the Playlist class. Playlists with fewer songs on them...
In javascript, Write a compareTo method for the Playlist class. Playlists with fewer songs on them come first. Playlists with the same number of songs come in alphabetical order by playlist name. Playlists with the same number of songs and same name can be considered equivalent (though this obviously isn’t exactly true).
5) Write a JavaScript script that will ask the user to enter in the length of...
5) Write a JavaScript script that will ask the user to enter in the length of the side of a cube. (all the sides of a cube are equal) Based on the value that is entered by the user from the keyboard, calculate each of the following and assign your results to variables. 1. volume of the cube 2. surface area of the cube 3. volume of the largest sphere that could fit in the box. 4. surface area of...
JAVA PLEASE!! Write a value-returning method, isVowel, that returns the value true if a given character...
JAVA PLEASE!! Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, and otherwise returns false. Also write a program to test your method. 2) Write a program that prompts the user to input a sequence of characters and outputs the number of vowels. (Use the method isVowel written in Programming Exercise 1.)
Write a javascript program that computes the total cost for a five year car lease. The...
Write a javascript program that computes the total cost for a five year car lease. The program starts with a monthly leasing amount and a yearly increase in percent. The program then outputs the total amount paid for each year and the total overall cost of the lease.
1. Determine the level of measurment of the data set. "The length (in seconds) of songs...
1. Determine the level of measurment of the data set. "The length (in seconds) of songs on an album." 2. Identify the statistical study that would be best to use and collect data for the following. "An engineer wants to test the strength of a bridge during an earthquake."
Write a java program (use value returning method) that gives simple math quizzes. The program should...
Write a java program (use value returning method) that gives simple math quizzes. The program should display two random integers from 1 to 100 that are to be added, such as:    47 + 29 The program allows the user to enter the answer. If the answer is correct, display “congratulations”. If the answer is incorrect, the program should show the correct answer. Your result should look like, for example:    47 + 29 Enter your answer: 1 Wrong, the right answer...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
The length of songs in a collector’s iTunes album collection is uniformly distributed from two to...
The length of songs in a collector’s iTunes album collection is uniformly distributed from two to 3.5 minutes. Suppose we randomly pick five albums from the collection. There are a total of 43 songs on the five albums a) Find the probability that 43 songs will last on average more than 2.78 minutes b) Find the probability that on average 43 songs will last less than 2.8 mnutes
The length of songs in a collector's iTunes album collection is uniformly distributed from two to...
The length of songs in a collector's iTunes album collection is uniformly distributed from two to 3.1 minutes. Suppose we randomly pick five albums from the collection. There are a total of 43 songs on the five albums. 1. Give the distribution of X. (Round your answers to four decimal places.) 2. Find the first quartile for the average song length. (Round your answer to two decimal places.) 3. Find the IQR (interquartile range) for the average song length. (Round...
PYTHON! Exercise 3 - Total Line length Write a python function that will return the total...
PYTHON! Exercise 3 - Total Line length Write a python function that will return the total length of line that passes through any number of provided points ( (x,y) ). The points should be passed as individual tuples or lists. The function should also have a parameter (True or False) to indicate whether the line should start from the origin, and that parameter should default to False. If True, the returned value should include the distance from the origin to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT