Given two numbers X and Y, write a function that: 1 returns even numbers between X and Y, if X is greater than Y else it returns | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 4

Given two numbers X and Y, write a function that: 1 returns even numbers between X and Y, if X is greater than Y else it returns

solve these. Given two numbers X and Y, write a function that: 1 returns even numbers between X and Y, if X is greater than Y else it returns odd numbers between x and y For instance, take the integers 10 and 2 . the function would return all the even numbers between 2 and 10. Specification numberGame(x, y) Return a list of odd or even number between two integers X and Y Parameters x: Number - The first integer provided y: Number - The second integer provided Return Value Number - a list of odd or even numbers between x and y Examples: 12, 0 => [2,4,6,8,10]e courage to pursue them." Walt Disney

5th Oct 2018, 8:24 PM
ohwo oghenekaro
ohwo oghenekaro - avatar
5 Answers
+ 1
const number_game = (x, y) => { // Code here let numArray = []; let numArray2 = [] /*if (x < y) { for (i=x+1; i<y; i++) { if (i%2 == 0) { numArray.push(i); } } } */ if(x<y) { for (i=x+1; i<y; i++) { if (i%2 != 0) { numArray.push(i); }else { numArray2.push(i) } } } else{ if(x>y){ for (i=y+1; i<x; i++) { if (i%2 != 0) { numArray.push(i); }else { numArray2.push(i) } } } } return numArray } console.log(number_game(4, 22)) change the return statement (numArray/ numArray2) depending on the expected array (odd or even)
28th Nov 2018, 9:51 AM
Jerry
0
If you were to use javascript: function numberGame(x, y) { var numArray = []; if (x > y) { for (i=y+1; i<x; i++) { if (i%2 == 0) { numArray.push(i); } } } else { for (i=x+1; i<y; i++) { if (i%2 != 0) { numArray.push(i); } } } return numArray; } var xValue = parseInt(prompt("Enter value for X")); var yValue = parseInt(prompt("Enter value for Y")); alert (numberGame(xValue, yValue)); So if you enter 12 and 0, the result will be 2,4,6,8,10. And if you enter 0 and 12, the result will be 1,3,5,7,9,11. You could also add some validations as needed.
5th Oct 2018, 9:34 PM
Alex
0
I imagine that in this also you tried your best, and in this also you have not posted your try... Coincidence? Maybe... Next time, please, post your try because its hard differentiate who want learn from who want own assignements made by others
5th Oct 2018, 9:47 PM
KrOW
KrOW - avatar
0
I think you need to fix the relevant tags for the original post, at least, indicate a language involved. As it is now, your "relevant tags" consists of irrelevant words.
6th Oct 2018, 3:34 PM
Ipang
0
I'm thinking of new way for solving this problem. My code below: function test(x, y) { for (let k = x; x < y; k++) { if (x > y && k % 2 == 0) { alert(k) else (x<y && k%2!=0){ alert(k)} } } } test(12, 0); But the code is not working. Please kindly help me debug the code. Open to all suggestions.
20th Dec 2018, 7:27 AM
Oladejo Tunde Oluwatosin