diff --git a/GitHub Card/js/script.js b/GitHub Card/js/script.js index 5c6d049..1636716 100644 --- a/GitHub Card/js/script.js +++ b/GitHub Card/js/script.js @@ -8,21 +8,34 @@ const usernameInput = document.querySelector("#username"); -async function profile(name="shouryasinghrathore") { - - let quotes = await fetch(`https://api.github.com/users/${name}`) - let apiInfo = await quotes.json(); - console.log(apiInfo) - image.setAttribute('src', apiInfo.avatar_url); - newname.innerHTML =apiInfo.login; - console.log(apiInfo.login) - following.innerHTML = apiInfo.following; - followers.innerHTML = apiInfo.followers; - id.innerHTML = apiInfo.id; - +async function profile(name = "shouryasinghrathore") { + try { + let response = await fetch(`https://api.github.com/users/${name}`); + + if (response.status === 404) { + profile(); + document.getElementById("inputValue").value = ""; + alert("Enter Valid Username"); + } else if (response.ok) { + let apiInfo = await response.json(); + console.log(apiInfo); + image.setAttribute('src', apiInfo.avatar_url); + newname.innerHTML = apiInfo.login; + console.log(apiInfo.login); + following.innerHTML = apiInfo.following; + followers.innerHTML = apiInfo.followers; + id.innerHTML = apiInfo.id; + } else { + console.error("Error fetching user data"); + alert("Error fetching user data"); + } + } catch (error) { + console.error("An error occurred:", error); + } } + function processInput() { let inputValue = document.getElementById("inputValue").value; if (inputValue.trim() !== "") { diff --git a/Random Password Generator/js/script.js b/Random Password Generator/js/script.js index 062b401..5aff016 100644 --- a/Random Password Generator/js/script.js +++ b/Random Password Generator/js/script.js @@ -12,6 +12,10 @@ document.addEventListener("DOMContentLoaded", function () { function generatePassword() { const length = parseInt(passwordLengthInput.value); + if(!length) { + alert("Please enter a valid password length."); + return; + } const includeUppercase = includeUppercaseCheckbox.checked; const includeLowercase = includeLowercaseCheckbox.checked; const includeNumbers = includeNumbersCheckbox.checked;