I have a user object having last_level property
I am passing it in my express route as follows :
app.get('/game', (req, res) => {
res.render('main.ejs', { user: req.user })
})
I want to access it in my JS script file.
After some research, I tried this...
var x = <%- user.last_level %>
But its not working (not giving me value of last_level to assign it to variale x). Help me out on this please.
This is my whole function -
window.onload = function () {
var x = <%- user.last_level %>
if (x === "Easy") {
console.log("easy")
} else if (x === "Hard") {
console.log("hard")
} else if (x === "Pro") {
console.log("pro")
}
console.log(x)
};
var x = user.last_levelwithout tags.var x = user.last_levelthough why would you need to set it to a variable if its there already?user is not defined at window.onloaderror @federico-moretti