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

102
Views
My Javascript code always returns 10 or 11 and never returns the other random numbers which have not been specified in the if condition

This is my Javascript code:

function getRandomCard(){
        randomCard = Math.floor(Math.random()*13)+1
    
        if (randomCard === 1){
            return 11
        }
        
        else if (11 <= randomCard <= 13){
            return 10   
        }
    
        else{
            return randomCard
        }
    }
    
 console.log(getRandomCard())

I have linked it to an HTML file with a button to call this function on getting clicked. Every time it is, it only returns 10 or 11. What could be wrong with my code?

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

0

Not sure maybe your if condition is wrong..

function getRandomCard(){
        randomCard = Math.floor(Math.random()*13)+1
    
        if (randomCard === 1){
            return 11
        }
        
        else if (11 <= randomCard && randomCard <= 13){
            return 10   
        }
    
        else{
            return randomCard
        }
    }
    
 console.log(getRandomCard())

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!