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).
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 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...
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."
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...
1)Write pseudocode for calculating the average text length (in number of words) for NLTK corpus 2)...
1)Write pseudocode for calculating the average text length (in number of words) for NLTK corpus 2) Write Python code for your average-text-length pseudocode.
Palindrome Javascript I am trying to write this javascript function to check if a number is...
Palindrome Javascript I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. This is the code i have, but it doesnt work. Code: let convertButton = document.getElementsByClassName("btn")[0]; let userInput = document.getElementById("number").value; let results = document.getElementById("result").value; convertButton.addEventListener("click", function (event) { event.preventDefault(); console.log(userInput); if (validatePalidrome(userInput)) document.getElementById("result").innerHTML = "true"; else document.getElementById("result").innerHTML = "false"; }); function validatePalidrome(numbers) { let...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., 12321 This is the code i have, but it doesnt work. PLEASE MAKE SURE IT WORK BEFORE POST ANSWER, I GOT @ CODE THAT DID WORK BEFORE HTML JavaScript Palindrome Exercise rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" /> Palindrome Enter a positive number: Is this a palindrome? No...
Calculating the Value of Ending Inventory and Cost of Goods Sold: Perpetual Method Total Units Unit...
Calculating the Value of Ending Inventory and Cost of Goods Sold: Perpetual Method Total Units Unit Cost Total Cost Beginning inventory on hand 1-Jan 60,000 $2.00 $120,000 Purchases during month 5-Jan 103,600 $2.00 $207,200 20-Jan 293,900 $2.10 $617,190 Sales of inventory 25-Jan 383,900 Beginning inventory at 1-Feb 73,600 Purchases during month 8-Feb 282,200 $2.20 $620,840 23-Feb 153,500 $2.60 $399,100 Sales of inventory 27-Feb 407,600 Ending Inventory 101,700 LIFO Jan Feb Cost of goods sold Cost of goods sold Ending inventory...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT