-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonPart4.html
More file actions
78 lines (69 loc) · 2.93 KB
/
jsonPart4.html
File metadata and controls
78 lines (69 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<html>
<head>
<meta charset="UTF-8">
<title>JSON Example</title>
</head>
<style>
body {
font-size: 20px;
text-decoration: none;
padding: 10px;
}
</style>
<body>
<form>
Genre:
<select name="genre" id="genre">
<option value="Pop"> Pop </option>
<option value="R and B/Soul"> R and B/Soul </option>
<option value="Alternative/Indie"> Alternative/Indie </option>
<option value="Hip-Hop/Rap"> Hip-Hop/Rap </option>
<option value="Electric"> Electric </option>
<option value="R and B"> R and B </option>
<option value="Afrobeats"> Afrobeats </option>
<option value="Jazz Rap"> Jazz Rap </option>
<option value="Electronic"> Electronic </option>
</select>
<input type="button" value = "Filter" id="button">
</form>
<div id="part4"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$("#button").click(function() {
var genreOption = document.getElementById("genre").selectedIndex;
var picked = document.getElementById("genre").options[genreOption].value;
$.get("https://laurenlangbort.github.io/json-practice-hw7/songs.json",
function( data )
{
var display = "<ul>";
data.forEach(function(song)
{
if (Array.isArray(song.genres))
{
if(song.genres.includes(picked))
{
display += "<li>"
+ song.song + "<br>"
+ "Artist: " + song.artists + "<br>"
+ "Genre: " + song.genres.join(", ") + "<br>"
+ "Year: " + song.year + "<br><br>" + "</li>";
}
} else if (picked == song.genres)
{
display += "<li>"
+ song.song + "<br>"
+ "Artist: " + song.artists + "<br>"
+ "Genre: " + song.genres + "<br>"
+ "Year: " + song.year + "<br><br>" + "</li>";
}
});
display += "</ul>";
document.getElementById("part4").innerHTML = display;
});
});
});
</script>
</body>
</html>