How to edit the render information with if else in ejs file

202 Views Asked by At

Hi i am trying to add condition for the render value in ejs file. i want to do something if value is equal to blah blah. I tried as shown below.

<% if (user) { %>
    <div class="user_info">
        <div>
            <p>User Name<%= user.username %></p>
            <p>User bio<%= user.user_bio %></p>
            //here i want to put if else statement
            //like this
            <% if (user.user_age = null){ %>
                <p>Your age is not defined. </p>
            <% } %>
            <% else if (user.user_age = 10){ %>
                 <p>You are a <%= user.user_age %> old tween!! </p>
            <% } %>
            <% else { %>
                 <p>You are a <%= user.user_age %> old Adult!! </p>
            <% } %>
        </div>
    </div>
<% } else { %>
    <p>No User!</p>
<% } %>

Clearly this if else statement i tried is not working. How can i do this?

1

There are 1 best solutions below

1
Mohak Gupta On

I have worked on this type of project something like that of whatsapp web, its going to be a little hard because there are not many good tutorials out there, but I can give you some tips or steps you need to follow, to give the code would be very lengthy and its propriety code that I've worked on so I cant share that.

First of all to connect to server using a mobile or qr scanner you have to have a private or seperate socket to connect to the server. For that you can have to use web sockets which is a big task but you can use a simple socket library socket.io its fairly easy. You will have to create a unique socket and key which you need to pass through the r itself(you have to render the qr code image through node js with the key as value) for that you can use 'qrcode' npm package. For now your task here is done.

The difficult part starts here. You have to make an android/ios app to use that data which will use it in its own way, for ex in whatsapp when you can qr code from app it logs you in to your account and load contacts, messages, etc on the screen.

Im not an android or app developer for now, that part has to solved by you.