From 88bf22f2db83ec759f27c6145da82629e3e71374 Mon Sep 17 00:00:00 2001 From: Techie-AgrawalJi <2802jayagrawal@gmail.com> Date: Sun, 24 Aug 2025 17:32:24 +0530 Subject: [PATCH] added new files --- 252queryStrings.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 25index.html | 20 ++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 252queryStrings.js create mode 100644 25index.html diff --git a/252queryStrings.js b/252queryStrings.js new file mode 100644 index 0000000..edac308 --- /dev/null +++ b/252queryStrings.js @@ -0,0 +1,51 @@ +let url = "http://universities.hipolabs.com/search?country="; +// const axios = require("axios"); +let btn = document.getElementById("search"); +let inpCountry = document.getElementById("country"); +let inpState = document.getElementById("state"); +inpCountry.addEventListener("keypress", async (e) => { + if (e.key === "Enter") { + // let country = document.getElementById("country").value; + searchUniversities(); + } +}); +inpState.addEventListener("keypress", async (e) => { + if (e.key === "Enter") { + // let country = document.getElementById("country").value; + searchUniversities(); + } +}); +btn.addEventListener("click", async () => { + searchUniversities(); +}); + +async function getNames(url) { + try { + let result = await axios.get(url); + return result.data; + } catch (error) { + return error; + } +} + +function show(names) { + let list = document.getElementById("list"); + list.innerText = ""; + for (college of names) { + let li = document.createElement("li"); + li.innerHTML = `College : ${college.name}, State : ${college["state-province"]}`; + list.appendChild(li); + } +} + +async function searchUniversities(){ + let names = await getNames(url + inpCountry.value); + if (inpState.value) { + names = names.filter( + (uni) => + uni["state-province"] && + uni["state-province"].toLowerCase() === inpState.value.toLowerCase() + ); + } + show(names); +} \ No newline at end of file diff --git a/25index.html b/25index.html new file mode 100644 index 0000000..78e8a6c --- /dev/null +++ b/25index.html @@ -0,0 +1,20 @@ + + + +
+ + +