frankcollins3 / fill_container

codecamp team project updated with new icon screen menu + puppeteer icon search, GraphQL, redux, relational psql !mongo, and accuweatherAPI
1 stars 0 forks source link

using variables / string interpolation in regex [9:42pm] #231

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

const handleClick = (index:number) => { console.log($(#timeSpan${index}))

let indexTargetSpan = $(`#timeSpan${index}`)[0]
console.log('indexTargetSpan')
console.log(indexTargetSpan)
console.log(indexTargetSpan.innerText)

let todaydate = new Date()
let year = todaydate.getFullYear()

// returns this string: Sun Jun 18 2023 21:40:52 GMT-0400 (Eastern Daylight Time)

let timetoday = todaydate.toString().match(/{year}\s(.+?)\sGMT/)
console.log('timetoday')
console.log(timetoday)

how to use that variable in the regex so that a hard-coded '2023' that does successfully return: "21:40:52" 👎 and that hard-coded value doesn't work when deployed in production 6 months from now when .getFullYear() returns 2023

frankcollins3 commented 1 year ago

didn't even need to do regex to get the date the new Date() comes with such methods'