Browse Source

join categories

modals-to-spa
stingl 4 years ago
parent
commit
3ae18d5d24
  1. 14
      js/JokeService.js

14
js/JokeService.js

@ -1,20 +1,20 @@ @@ -1,20 +1,20 @@
class JokeService {
constructor(category = ['programming', 'coding', 'development'], lang = 'en') {
this.category = Array.isArray(category) ? category : [category];
constructor(categories = ['programming', 'coding', 'development'], lang = 'en') {
this.categories = Array.isArray(categories) ? categories : [categories];
this.lang = lang;
this.apiBaseUrl = 'https://v2.jokeapi.dev/joke/'
}
setCategory(category) {
this.category = Array.isArray(category) ? category : [category];
this.categories = Array.isArray(category) ? category : [category];
}
tell() {
let service = this;
axios.get(
service.apiBaseUrl + getRandomItem(service.category) + '?lang=' + service.lang
service.apiBaseUrl + service.categories.join(',') + '?lang=' + service.lang
).then((response) => {
if (response.data.error === false) {
service.show(response.data);
@ -43,10 +43,6 @@ function showNotification(text) { @@ -43,10 +43,6 @@ function showNotification(text) {
body: text
});
} else {
// alert(text);
console.warn('Notifications sind nicht erlaubt.')
}
}
function getRandomItem(items) {
return items[Math.floor(Math.random()*items.length)];
}