/
index.js
26 lines (21 loc) · 862 Bytes
/
index.js
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
import './app.scss';
const lyricsContainer = document.getElementById('lyrics');
const artistOutput = document.getElementById('artistOutput');
const titleOutput = document.getElementById('titleOutput');
const submitBtn = document.getElementById('submitBtn');
function getLyrics(artist, title) {
fetch('https://api.lyrics.ovh/v1/' + artist + '/' + title)
.then((resp) => resp.json())
.then(function (data) {
let lyrics = data.lyrics;
lyricsContainer.innerHTML = lyrics;
artistOutput.innerHTML = artist;
titleOutput.innerHTML = title;
});
}
submitBtn.addEventListener('click', function (e) {
e.preventDefault();
let artistInput = document.getElementById('artist').value;
let titleInput = document.getElementById('title').value;
getLyrics(artistInput, titleInput);
});