the below function checks if a number is odd or not and logs them
function OddNumFinder(x) {
if (x%2==1) {
y = console.log(x ' is a odd number');
x = x%2
return console.log(x);
}
}
im_num = []
this function create an array of random number
function collConjecture(x) {
while (x !== 1) {
if (x%2 == 1) {
x = (x*3) 1
} else {
x = x/2
}
im_num.push(x)
}
}
this works
collConjecture(26)
list = im_num
console.log(list);
i don't know what i'm doing wrong here
var yetha = OddNumFinder(collConjecture(26))
console.log(yetha);
CodePudding user response:
That's because your function OddNumFinder
requires a number, but you are not passing a number as your function collConjecture
returns nothing.
CodePudding user response:
Do the following changes
//Takes a number and checks for odd
function OddNumFinder(x) {
if (x%2 == 1) {
console.log(x ' is a odd number');
x = x%2
}
}
function collConjecture(x) {
im_num = []
while (x !== 1) {
if (x%2 == 1) {
x = (x*3) 1
} else {
x = x/2
}
im_num.push(x)
}
return im_num
}
//call map on each number to check for odd
collConjecture(26).map(item => {
OddNumFinder(item)
})
Output :-
13 is a odd number
5 is a odd number
1 is a odd number