-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
40 lines (32 loc) · 1.25 KB
/
main.js
File metadata and controls
40 lines (32 loc) · 1.25 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
window.onload = refresh;
async function refresh() {
const response = await fetch("https://dog.ceo/api/breeds/image/random");
const dogs = await response.json();
document.getElementById("pic").src = dogs.message;
var radioButtons = document.getElementsByName("star");
for (var i = 0; i < radioButtons.length; i++) {
radioButtons[i].checked = false;
}
const ratingContainer = document.querySelector(".rating-container");
const ratingInputs = ratingContainer.querySelectorAll('input[type="radio"]');
let selectedRating;
ratingInputs.forEach((input) => {
input.addEventListener("change", (event) => {
selectedRating = event.target.value;
const text = document.getElementById("rate");
const temp = selectedRating;
text.innerHTML ="Last Dog Rated: " + temp + " Star";
});
});
}
const button = document.querySelector("button");
button.addEventListener("click", refresh);
const ratingContainer = document.querySelector(".rating-container");
const ratingInputs = ratingContainer.querySelectorAll('input[type="radio"]');
let selectedRating;
ratingInputs.forEach((input) => {
input.addEventListener("change", (event) => {
selectedRating = event.target.value;
selectedRating = parseInt(selectedRating);
});
});