In: Computer Science
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).
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.