Giter VIP home page Giter VIP logo

conditional-operators-quiz's Introduction

#Condition Operators Quiz

Objectives

  1. Test your understanding of the ternary operator
  2. Understand when to use the ternary operator
  3. Understand that use of statement modifiers (trailing if and trailing unless statements)
  4. Understand the use of trailing unless statement

???

Quiz

?: Which of the following if statements is a good candidate for using a ternary operator instead?

(X)

if condition_a
  something
else
  something_else
end

( )

if condition_a
  something
elsif condition_b
  something_else
else
  something_even_more_different
end

?: Let's convert the correct answer above using a ternary operator. Which of the following is the correct way to do that?

( )

condition_a ? something : condition_b

( )

condition_a ? something : (conditional_b ?something_else : something_even_more_different)

(X)

condition_a ? something : something_else

( )

condition_a ? something_else : something

?: When is it a good idea to use an if conditional over a ternary?

( ) When the if statement is complex with multiple elseif conditions ( ) When it would require a nested ternary statement ( ) When the ternary statement takes up more than one line (X) All of the above

?: What will this code print out:

name = "Steven"
puts "Hi, #{name}" if name == "Steven"

( ) "Hi, #{name}" (X) "Hi, Steven" ( ) Nothing

?: What will this code print out:

name = "Steven"
puts "Hi, #{name}" unless name == "Steven"

( ) "Hi, #{name}" ( ) "Hi, Steven" (X) Nothing

?: If you are unsure whether to use the ternary operator, or the if statement, which should you use?

(X) if statement ( ) ternary statement

???

View Condition Operators Quiz on Learn.co and start learning to code for free.

conditional-operators-quiz's People

Contributors

annjohn avatar joshuabamboo avatar matbalez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.