Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

passing variables from pug/jade to front side javascript

i am having trouble sending varibles from my pug template to my frontside javascript file. i want to store users name and treehouse account in a variable everytime they are redirected to their profile page. with the code provided below, i can successfully send the title variable and the name variable. However, when i add another variable in the if statement (even if it is practically the same code but different name ex namee), it will only successfully log all three on the profile page! when i visit a different page other than profile page, name and title will log but i receive and error for the user variable holding the treehouse info. any help or information is beyond appreciated ive been stuck for a full day!!!

badges.js:2 Uncaught ReferenceError: user is not defined at badges.js:2

express code:

return res.render('profile', { title: 'Profile', name: user.name, quote: user.quote, treehouse: user.treehouse });

pug code (in my footer include file):

script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js')
script.
    title="#{title}";
script.
    if (title === "Profile"){
        name = "#{name}";
        user = "#{treehouse}";
        }
script(src='/static/javascript/flikr.js')
script(src='/static/javascript/badges.js') 

javascript code: right now im only logging the info to console to test.

NOTE: if i put the varibles in an array and log it it will show useraccountinfo,name but when i try to log a certain element. info[0] is only logs the first character not the whole element!! var info = new Array("#{treehousename}","#{name}" );