Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get an output of next `ten` odd and even numbers after entering any random number in javascript

I want to have a logic where if I enter an even number I want next 10 even numbers to be printed and If I enter an odd number, I want next 10 odd numbers to be printed. In my this logic i am getting an output of odd & even together and also i’m getting restricted to numbers from only 0-15 which I don’t want. If someone can please help me rectifying the logic

JS

for (var x=0; x<=15; x++) {
  if (x === 0) {
          console.log(x +  " is even");
  }
  else if (x % 2 === 0) {
          console.log(x + " is even");   
  }
  else {
          console.log(x + " is odd");
  }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

let inputval = 2;
for (let x=1; x<=10; x++) {
console.log(inputval + x * 2)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading