mercredi 19 juin 2019

Not getting expected answer

Code not returning the correct answer.

I've tired assigning a value to the animal choices. I've put it in the def and outside of it.

puts "Choose your favorite: cats or dogs"
choose = gets
cats = 1
dogs = 2

def favorite_animal (number)

    remainder_when_divided_by_2 = number % 2

    if remainder_when_divided_by_2 == 0
       return "Ken does too."
    end

    if remainder_when_divided_by_2 == 1
       return "Dogs are better!"
    end

end

If the user enters Cats the answer "Ken does too!" should show. If the user enters Dogs the answer "Dogs are better!" should show. All I've gotten is 0 or 1 as an answer.

Aucun commentaire:

Enregistrer un commentaire