From 13e45aa06d7e1a54f0e82cef0fdc1c76204d8c66 Mon Sep 17 00:00:00 2001 From: Jacob Asper Date: Sat, 11 Jun 2022 23:18:39 -0400 Subject: [PATCH] Added comments to getMatches function --- public/js/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/js/main.js b/public/js/main.js index 6aeac1a..c87137a 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); } }