I am a beginner when it comes to node.js and async programming. My current project involves creating a program that shuffles a Spotify playlist. I have managed to store the user's playlists in an array for easier access.
My goal is to present this array on the webpage so that the user can choose one. Once the selection is made, I plan to proceed with the program using the chosen element. Here is a snippet of the code I have developed so far:
// Working with callback functions
function plCallback(selected_playlist) {
playlist_id =
console.log(playlist_id);
}
function getPlaylist(body, plCallback) {
// Retrieving user playlists
for (var i = 0; i < body.items.length; i++) {
playlistArray.push({'name': body.items[i].name, 'id': body.items[i].id});
}
// Displaying the playlists for user selection
var selPlaylist = document.getElementById('playlist-drop');
for (var i = 0; i < playlistArray.length; i++) {
var opt = playlistArray[i].name;
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
// Passing the selected playlist to the Callback
var dropdown_return = document.getElementById('playlist-drop');
var selected_playlist = dropdown_return.options[dropdown_return.selectedIndex].value;
plCallback(selected_playlist);
}
As someone new to JavaScript and Node, I am struggling to find the right resources to guide me through this process.
In essence, my task involves collecting Spotify playlists into a JavaScript array, allowing the user to pick one, and then proceeding with the chosen playlist's information within the program.