jaredden1 / Get-Me-Fit-App

Get Me Fit
https://get-fit-tracker-1b767e883070.herokuapp.com/
MIT License
0 stars 2 forks source link

Grow Snippet - AAG #21

Open harrymohney opened 1 year ago

harrymohney commented 1 year ago

Screenshot 2023-08-18 at 10 57 46 AM

Consolidation of our 7 'new_...ejs' files into a more efficient code body with less code and same options.



maker-jws commented 1 year ago

Inside your new form you might want to consider using a for loop to iterate over a range

assuming you have a set range context variables (rangeStart, rangeStop, weightIncrement) you could write an EJS iterator like

<select name="weight" ...rest of your attributes here>
<!-- your default value -->
<% for (let weight= rangeStart; weight<=rangeStop; weight+=weightIncrement){ %>
   <option value="<%=weight%>"><%=weight%>lbs</option>
<%}%>
</select>

Any time you find yourself writing a lot of repetitive code you might have an opportunity to stop, step back, and study the problem more carefully, looking for optimizations.

Additionally, with this dynamic approach you could create just one page that changes the content depending on the state of your model data. Or dynamically change your weight ranges depending on the selected drop down type using client side DOM manipulation (TTT team might be able to help you out with that approach!)

Over all, a great candidate for a refactor - good luck!