Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
display element based on comparison operator

i have a problem with comparison operator, in my forum i want to show an element if the number of post is <= 10, <=50 and so on....but if <=50 is displayed i want to hide <=10.

My code:

if (userPosts  <= 10){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-baby autopost"/> less than 10 posts</span>
        );
      }
      if (userPosts  <= 50){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-child autopost"/> less than 50 posts</span>
        );
      }
      if (userPosts  <= 100){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-bullhorn autopost"/> less than 100 posts</span>
        );
      }

the problem is that if a user have 200 posts, i see all of these 3 elements displayed, and i want to display only <=100 instead.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can make a double condition in your if statement :

if (userPosts  <= 10){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-baby autopost"/> less than 10 posts</span>
        );
      }
      if (userPosts  <= 50 && userPosts > 10){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-child autopost"/> less than 50 posts</span>
        );
      }
      if (userPosts  <= 100 && userPosts > 50){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-bullhorn autopost"/> less than 100 posts</span>
        );
      }

EDIT or use else if statement :

if (userPosts  <= 10){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-baby autopost"/> less than 10 posts</span>
        );
      }
      else if (userPosts  <= 50){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-child autopost"/> less than 50 posts</span>
        );
      }
      else if (userPosts  <= 100){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-bullhorn autopost"/> less than 100 posts</span>
        );
      }
about 4 years ago · Juan Pablo Isaza Report

0

You can use an else-if block as:

if (userPosts  <= 10){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-baby autopost"/> less than 10 posts</span>
        );
      }
     else if (userPosts  <= 50){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-child autopost"/> less than 50 posts</span>
        );
      }
      else if (userPosts  <= 100){
        vnode.children.push(
          <span className="auto-badge"><i class="fas fa-bullhorn autopost"/> less than 100 posts</span>
        );
      }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!