Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

71
Views
i created two functions, both are working but when i when i put them together they are not

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);
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

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
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs