DEV Community

Madalina Pastiu
Madalina Pastiu

Posted on

Opposites Attract

Instructions:
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.

Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't.

Thoughts:
1.Checking if the petals number of each flower is even or odd.
2.Compare both the number of petals with each other to know if Timmy & Sarah are in love (1 flower has to have an even number of petals and one an odd number of petals)

Solution:

function lovefunc(flower1, flower2){
  const petalsFlower1 = flower1 % 2 === 0 ? true : false;
  const petalsFlower2 = flower2 % 2 === 0 ? true : false;
  return petalsFlower1 !== petalsFlower2 ? true : false
}
Enter fullscreen mode Exit fullscreen mode

This is a CodeWars Challenge of 8kyu Rank (https://www.codewars.com/kata/555086d53eac039a2a000083/train/javascript)

Top comments (0)