Currently, my if/else statement does not work correctly as it never goes to the else portion of my code. The node app takes in an argument (process.argv[3]) and uses that to pick the API to call. process.argv[4] is used to specify what to search (example "Yesterday") and works correctly if argument is provided. However, I want to have a default search if user leaves that argument blank. I'm unsure of why it never goes to the else portion of the code.
I'm new to programming so I'm sure this is stupid error on my part, but I've tried rewritting the statement and same issue. Any help would be greatly appreciated.
function getSpotifySongInfo() {
//4th node argument is reserved for the song user wants to select
//var query = process.argv[3];
if (query !== "") {
//could make this less repeating code by passing the song as a parameter?
spotifyClient.search({ type: 'track', query: query, limit: 1 }, function (err, data) {
if (!err) {
console.log("=============Artist==Track==Album==PreviewURL=============================");
console.log("Artist: " + data.tracks.items[0].artists[0].name);
console.log("Track: " + data.tracks.items[0].name);
console.log("Album: " + data.tracks.items[0].name);
console.log("Preview URL: " + data.tracks.items[0].preview_url);
} else {
console.log(err);
}
});
} else {
//need to make this specific for Ace of Base. For some reason it's not changing the query to reflect default song. I've tried commenting this portion out and just testing w/ a simple console.log("test") and nothing...
query = 'The Sign';
spotifyClient.search({ type: 'track', query: query, limit: 1 }, function (err, data) {
if (!err) {
console.log("=============Artist==Track==Album==PreviewURL=============================");
console.log("Artist: " + data.tracks.items[0].artists[0].name);
console.log("Track: " + data.tracks.items[0].name);
console.log("Album: " + data.tracks.items[0].name);
console.log("Preview URL: " + data.tracks.items[0].preview_url);
} else {
console.log(err);
}
});
}
}
Aucun commentaire:
Enregistrer un commentaire