Conditional Quiz Vowels

Objectives

You will answer a series of multiple choice questions to help you practice the following:

  1. Flow control and the use of if, elsif, and else statements.
  2. Flow control and the use of case statements.
  3. Using comparative operators.

The questions in this quiz are predicated on the idea of building methods that can determine if a letter is a vowel or a consonant. For the purposes of this quiz, vowels will be "a", "e", "i", "o", and "u" (sorry, but you're not in the club, "y").

Conditional Vowels

Checking for vowels with if, elsif, and else

We're building a method, vowels_with_if_elsif that will take in a letter and return true if that letter is a vowel and false if that letter is a consonant.

def vowels_with_if_elsif(letter)
  < fill me in!! >
end

Which of the following is the correct implementation of if, elsif, and else?

if letter == "a"
  true
elsif letter == "e"
  true
elsif letter == "i"
  true
elsif letter == "o"
  true
elsif letter == "u"
  true
else
  false
end

if letter = "a"
  true
elsif letter = "e"
  true
elsif letter = "i"
  true
elsif letter = "o"
  true
elsif letter = "u"
  true
else
  false
end

What would the following statement return?

letter = "b"

if letter == "a" || letter == "e" || letter ==  "i" || letter == "o" || letter == "u"
  "vowel"
else
  "not a vowel"
end

vowel
not a vowel

Checking for vowels with case

The method vowels_with_case takes in a letter as an argument and uses a case statement to determine if that letter is a vowel.

def vowels_with_case(letter)
  case letter
  < fill me in! > "a"
    true
  < fill me in! > "e"
    true
  < fill me in! > "i"
    true
  < fill me in! > "o"
    true
  < fill me in! > "u"
    true
  else
    false
  end
end

Which keyword correctly replaces < fill me in! >?

if
elsif
when
while

Which of the following methods would correctly return true when given the letter "o" as an argument?

def vowels_with_if_single_line(letter)
  true if letter == "a" || letter == "e" || letter == "i" || letter == "o" || letter == "u"
end

def vowels_with_if_single_line(letter)
  true if letter == "a" && letter == "e" && letter == "i" && letter == "o" && letter == "u"
end

def vowels_with_if_single_line(letter)
  true if letter == "a" || if letter == "e" || if letter == "i" || if letter == "o" || if letter == "u"
end

View Quiz: Practicing Conditionals with Vowels on Learn.co and start learning to code for free.

Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us