Suppose an ejs file for upvoting system:
<% if(clicked(post_id)==1) %>
// load green button
<%} else {%>
// load red button
<script>
function clicked(id){
if(currentUser.upvotes_downvotes===undefined)
return -1;
PreClicked = arr.find(clicked => {
return clicked.postId.equals(id);})
if(PreClicked === undefined)
return 0;
else if(PreClicked.type === "upvote")
return 1;
else if(PreClicked.type === "downvote")
return 2;
}
</script>
But I am getting clicked is not defined