-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (31 loc) · 1.15 KB
/
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
27
28
29
30
31
32
33
const userInput = document.getElementById("input");
const userClick = document.getElementById("submit");
const qrCodeImg = document.getElementById("img");
const loader = document.getElementById("loader");
userClick.addEventListener("click", () => {
getUserInput(userInput.value);
});
const getUserInput = (getValue) => {
// getValue = getValue.trimStart();
if (getValue.length == "") {
alert("Please fullfilled your Empty");
} else {
// Api url
const url = `https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=${getValue}`;
qrCodeImg.classList.toggle("hidden"); // on ➡️ Off turnIntoOn to 'Off'
loader.classList.toggle("hidden"); // Off ➡️ On turnIntoOff to 'On'
// fetchDatafromApi
const fetchApi = async () => {
await fetch(url).then((res) => {
//when we use fetch methode it return promises
qrCodeImg.setAttribute("src", res.url);
});
setTimeout(() => {
loader.classList.toggle("hidden"); // on ➡️ Off turnIntoOn to 'Off'
qrCodeImg.classList.toggle("hidden"); // Off ➡️ On turnIntoOff to 'On'
userInput.value = "";
}, 2000);
};
fetchApi();
}
};