-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (48 loc) · 2.09 KB
/
index.js
File metadata and controls
61 lines (48 loc) · 2.09 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
'use strict';
// Assuming you have a form element with the id "myForm" in your HTML.
const myForm = document.getElementById('myForm');
const answer = document.getElementById('answer');
const answer2 = document.getElementById('answer2');
const answer3 = document.getElementById('answer3');
myForm.addEventListener('submit', (event) => {
event.preventDefault();
const type = document.getElementById('type').value;
// Call the boredFetch function with the user input values.
boredFetch(type);
});
function addDom(info,info2,info3) {
// Display the activity info on the page.
answer.innerHTML = JSON.stringify(info);
let price = JSON.stringify(info2);
answer3.innerHTML = `People: ${JSON.stringify(info3)}`;
if (price == 0){
answer2.innerHTML = "Price: FREE"
} else if (price > 0 && price < 0.1){
answer2.innerHTML = "Price: Dirt Cheap";
} else if (price >= 0.1 && price < 0.2) {
answer2.innerHTML = "Price: Cheap";
} else if (price >= 0.2 && price < 0.3) {
answer2.innerHTML = "Price: Innexpensive";
}else if (price >= 0.3 && price < 0.4) {
answer2.innerHTML = "Price: Fair";
}else if (price >= 0.4 && price < 0.5) {
answer2.innerHTML = "Price: Middle of the Range";
}else if (price >= 0.5 && price < 0.6) {
answer2.innerHTML = "Price: Getting Pricey";
}else if (price >= 0.6 && price < 0.7) {
answer2.innerHTML = "Price: Kinda Expensive";
}else if (price >= 0.7 && price < 0.8) {
answer2.innerHTML = "Price: Too Steep";
}else if (price >= 0.8 && price < 0.9) {
answer2.innerHTML = "Price: Epensive";
}else if (price >= 0.9 && price < 1) {
answer2.innerHTML = "Price: Fit for a King";
}
}
function boredFetch( type) {
const apiUrl = `https://www.boredapi.com/api/activity?type=${type}`
fetch(apiUrl)
.then((response) => response.json())
.then((response) => addDom(response.activity,response.price,response.participants))
.catch((err) => console.error(`error:`,err));
}