0% found this document useful (0 votes)
9 views1 page

Code 2

The document outlines the code for a Song Recommendation App that takes user input for mood and suggests songs and artists based on that mood. It includes event handlers to collect user input, filter song and artist lists, and display recommendations on the screen. The code also handles invalid inputs by logging error messages to the console.

Uploaded by

vistabassari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Code 2

The document outlines the code for a Song Recommendation App that takes user input for mood and suggests songs and artists based on that mood. It includes event handlers to collect user input, filter song and artist lists, and display recommendations on the screen. The code also handles invalid inputs by logging error messages to the console.

Uploaded by

vistabassari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

3/10/23, 7:37 AM https://bakerfranke.github.

io/codePrint/

Song Recommendation App

1 //Event handlers (1-12):


2 // User input is collected using getText
3 // The songRecommendations function is called when the user inputs mood
4 onEvent("moodInput", "input", function( ) {
5 var input = getText("moodInput");
6 songRecommendations(input);
7 });
8
9 // The screen is set to homeScreen
10 onEvent("returnButton", "click", function( ) {
11 setScreen("homeScreen");
12 });
13
14 //variables/lists (14-17):
15 var songList = getColumn("Song Recommendations Based On Mood", "Song Title");
16 var artistList = getColumn("Song Recommendations Based On Mood", "Artist");
17 var moodList = getColumn("Song Recommendations Based On Mood", "Mood");
18
19 // filtered lists (19-21):
20 var filteredSongList = [];
21 var filteredArtistList = [];
22
23 // The function traverses through every item in the list that matches the user's input
24 //If TRUE, it's added to the filtered list
25 //The screen changes, and the filtered list is then displayed
26 //If FALSE, the console log displays an error message
27 //This lets the user know their input was invalid
28 // mood {string} - parameter for the selected mood
29 function songRecommendations(mood) {
30 filteredSongList = [];
31 filteredArtistList = [];
32
33 for (var i = 0; i < moodList.length; i++) {
34 if (mood == moodList[i]) {
35 appendItem(filteredSongList, songList[i] + "\n");
36 appendItem(filteredArtistList, artistList[i] + "\n");
37 setScreen("recommendationScreen");
38 setText("artistText",filteredArtistList.toString());
39 setText("songTitleText", filteredSongList.toString());
40 console.log("Your music: " + filteredSongList + "\n" + "Artists: " + filteredArtistList);
41 } else {
42 console.log("Input is invalid. Make sure that your letters are all lowercase and that you entered a valid mood
43 }
44 }
45 }
46
47
48 /*
49 Media courtesy: Song Dataset - created by me
50 */
51
52
53 /*
54 //Testing:
55
56 // Call 1:
57 songRecommendations("happy");
58
59
60 // Call 2:
61 songRecommendations("angry");
62 */

https://bakerfranke.github.io/codePrint/ 1/2

You might also like