location.pathname is undefined

https://codepen.io/gsadopkgj/pen/oNJKxQR (i've put in the appropriate for the object property names - they now match the location.pathname)
20 Replies
lafayette
lafayetteOP13mo ago
but it says that this is the error in codepen tho (not on vscode): (this prevents the paragraph content from switching rn only the column headers are )
lafayette
lafayetteOP13mo ago
No description
lafayette
lafayetteOP13mo ago
but when i define it with let's say: let path = location.pathname; a new error occurs
lafayette
lafayetteOP13mo ago
No description
lafayette
lafayetteOP13mo ago
No description
Jochem
Jochem13mo ago
it's not saying location.pathname is undefined, it's saying that the key of sections identified by the value of location.pathname is undefined also let path = location.pathname doesn't do anything to location.pathname, it just stores the value (or lack thereof) in the path variable when I add a console.log for location.pathname, it outputs this:
"/cpe/boomboom/index.html"
"/cpe/boomboom/index.html"
and that key just doesn't exist in your sections array
lafayette
lafayetteOP13mo ago
ah im confused i try to call this singular javascript file on multiple sub html pages the index.html page is just one of them but in the sections bit i never call the index.html? i link all the other html subpages
Jochem
Jochem13mo ago
I'm not sure what you mean by "call the index.html"
lafayette
lafayetteOP13mo ago
No description
lafayette
lafayetteOP13mo ago
like here the index.html page is irrelevant for the sections code i don't need the index.html page
Jochem
Jochem13mo ago
okay, but location.pathname is set by the browser and contains "index.html"
lafayette
lafayetteOP13mo ago
i checked the location.pathname of only the specific subpages and included those is that wrong?
Jochem
Jochem13mo ago
I really don't know what you mean by that. regardless though, you're trying to access sections[pathname], but the first key in the sections object is Descriptions, Justification, and so on
lafayette
lafayetteOP13mo ago
kk thanks wait so shld i take this out: " let path = location.pathname; " then cus it's unecessary
Jochem
Jochem13mo ago
it's not really doing anything, if that's what you're asking
lafayette
lafayetteOP13mo ago
so how shld i go abt fixing that tho? cus i sorta need it like that do u understand what i'm trying to do? im having it so that the text changes for each html subpage but the text changing for each html subpage depends on the column headers which are 'description 'justification' and so on
Jochem
Jochem13mo ago
I think just switching from sections[path][currentOption] to sections[currentOption][path] and the same for the default after ||
lafayette
lafayetteOP13mo ago
wait i ahve it like this now
lafayette
lafayetteOP13mo ago
No description
lafayette
lafayetteOP13mo ago
so that shld fix it? hm it seems too one sec i think i fixed it with just changing how i'm accessing sections but this is only trying it one one subpage so lemme try the others
Want results from more Discord servers?
Add your server