How to generate random number between 1 and 10 in Node.js

2 Answers

0 votes
const n = Math.floor((Math.random() * 10) + 1); 
   
console.log(n);
  
  
  
    
/*
run:
   
2
    
*/

 



answered Jun 6, 2022 by avibootz
0 votes
for (let i = 0; i < 5; i++) {
    let n = Math.floor((Math.random() * 10) + 1); 
    console.log(n);
}
   
   
   
   
/*
run:
  
1
8
10
2
7
   
*/

 



answered Jun 6, 2022 by avibootz

Related questions

2 answers 185 views
1 answer 113 views
1 answer 229 views
2 answers 185 views
1 answer 133 views
...