diff --git a/public/js/main.js b/public/js/main.js index 57b0bba..c60856a 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,15 +1,21 @@ const btn = document.getElementById('keyword-btn'); btn.addEventListener('click', getMatches); +/** + * Name: getMatches + * Description: Find resources with keywords matching the user input + */ async function getMatches() { + //gets the input from the text box and trims white space and makes it lower case const keyword = document.querySelector('input').value.toLowerCase().trim(); try { const res = await fetch('/api'); const data = await res.json(); + // Filters array from the API for resources with keywords containing user value const matches = data.filter(resource => resource.keywords.some(str => str.includes(keyword))); renderMatches(matches); - } catch(err) { + } catch (err) { console.error(err); } }